예제 #1
0
    def preview(self, text):
        """Preview."""

        style = self.get_html_style()

        try:
            colors = evaluate_contrast(text)
            html = mdpopups.md2html(self.view, DEF_RATIO.format(style))
            if len(colors) >= 3:
                lum2 = colors[1].luminance()
                lum3 = colors[2].luminance()
                if len(colors) > 3:
                    luma = colors[3].luminance()
                    lumb = colors[4].luminance()
                    mn = min(luma, lumb)
                    mx = max(luma, lumb)
                    min_max = "<ul><li><strong>min</strong>: {}</li><li><strong>max</strong>: {}</li></ul>".format(
                        mn, mx)
                else:
                    min_max = ""
                html = ("<p><strong>Fg</strong>: {}</p>"
                        "<p><strong>Bg</strong>: {}</p>"
                        "<p><strong>Relative Luminance (fg)</strong>: {}</p>{}"
                        "<p><strong>Relative Luminance (bg)</strong>: {}</p>"
                        ).format(colors[2].to_string(**util.DEFAULT),
                                 colors[1].to_string(**util.DEFAULT), lum3,
                                 min_max, lum2)
                html += "<p><strong>Contrast ratio</strong>: {}</p>".format(
                    colors[1].contrast(colors[2]))
                html += CONTRAST_DEMO.format(colors[2].to_string(**util.COMMA),
                                             colors[1].to_string(**util.COMMA))
            return sublime.Html(style + html)
        except Exception:
            return sublime.Html(
                mdpopups.md2html(self.view, DEF_RATIO.format(style)))
예제 #2
0
    def preview(self, text):
        """Preview."""

        style = self.get_html_style()

        try:
            colors = evaluate(text)

            html = ""
            for color in colors:
                orig = Color(color)
                message = ""
                color_string = ""
                if not orig.in_gamut('srgb'):
                    orig = orig.fit("srgb")
                    message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
                    color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(
                        orig.to_string())
                    srgb = orig.convert('srgb', fit=True)
                else:
                    srgb = orig.convert('srgb')
                color_string += "<strong>Color</strong>: {}".format(
                    color.to_string(**util.DEFAULT))
                preview = srgb.to_string(**util.HEX_NA)
                preview_alpha = srgb.to_string(**util.HEX)
                preview_border = self.default_border
                temp = Color(preview_border)
                if temp.luminance() < 0.5:
                    second_border = temp.mix(
                        'white', 0.25, space="srgb").to_string(**util.HEX_NA)
                else:
                    second_border = temp.mix(
                        'black', 0.25, space="srgb").to_string(**util.HEX_NA)

                height = self.height * 3
                width = self.width * 3
                check_size = self.check_size(height, scale=8)

                html += tools.PREVIEW_IMG.format(
                    mdpopups.color_box([preview, preview_alpha],
                                       preview_border,
                                       second_border,
                                       border_size=2,
                                       height=height,
                                       width=width,
                                       check_size=check_size), message,
                    color_string)
            if html:
                return sublime.Html(
                    '<html><body>{}</body></html>'.format(style + html))
            else:
                return sublime.Html('<html><body>{}</body></html>'.format(
                    mdpopups.md2html(self.view, DEF_EDIT.format(style))))
        except Exception:
            return sublime.Html(
                mdpopups.md2html(self.view, DEF_EDIT.format(style)))
    def preview(self, value):
        if value == '':
            self.view.erase_regions('meu_expression_preview')
            return

        operation = "Subtractive" if self.args.get(
            "subtractive", False) else "Additive"

        if operation == "Additive":
            preview_scope = get_settings(
                "find.regex.additive.scope", 'region.greenish')
        else:
            preview_scope = get_settings(
                "find.regex.subtractive.scope", 'region.redish')

        regions = self.view.find_all(value, 0)

        if operation == 'Additive':
            regions = [r for r in regions if not self.view.sel().contains(r)]
        else:
            regions = [r for r in regions if self.view.sel().contains(r)]

        self.view.add_regions(
            'meu_expression_preview', [s for s in regions], preview_scope, '',
            sublime.DRAW_NO_FILL | sublime.PERSISTENT)

        return sublime.Html(
            f'<strong>{operation} Expression:</strong>' +
            f' <em>{html.escape(value)}</em><br/>' +
            f'<strong>Selections:</strong> <em>{len(regions)}</em>'
        )
예제 #4
0
    def preview(self, text: str):
        abbr = text.strip()
        snippet = None

        undo_preview(self.view)

        if abbr:
            try:
                preview_items = []
                for region, config in self.wrap_entries:
                    result = emmet.expand(abbr, config)
                    if self.instant_preview:
                        preview_items.append(
                            (region.begin(), region.end(), result))

                if preview_items:
                    self.view.run_command(
                        'emmet_wrap_with_abbreviation_preview',
                        {'items': preview_items})
            except:
                snippet = '<div class="error">Invalid abbreviation</div>'

        if snippet:
            return sublime.Html(popup_content(snippet))

        return None
예제 #5
0
    def preview(self, text):
        """Preview."""

        style = self.get_html_style()

        try:
            color = self.color_mod_class(text.strip())
            if color is not None:
                srgb = Color(color).convert("srgb")
                preview_border = self.default_border
                message = ""
                if not srgb.in_gamut():
                    srgb.fit("srgb")
                    message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
                preview = srgb.to_string(**util.HEX_NA)
                preview_alpha = srgb.to_string(**util.HEX)
                preview_border = self.default_border
                temp = Color(preview_border)
                if temp.luminance() < 0.5:
                    second_border = temp.mix('white',
                                             0.25).to_string(**util.HEX_NA)
                else:
                    second_border = temp.mix('black',
                                             0.25).to_string(**util.HEX_NA)

                height = self.height * 3
                width = self.width * 3
                check_size = self.check_size(height, scale=8)

                html = PREVIEW_IMG.format(
                    mdpopups.color_box([preview, preview_alpha],
                                       preview_border,
                                       second_border,
                                       border_size=1,
                                       height=height,
                                       width=width,
                                       check_size=check_size), message,
                    color.to_string(**util.DEFAULT))
            if html:
                return sublime.Html(style + html)
            else:
                return sublime.Html(
                    mdpopups.md2html(self.view, DEF_COLORMOD.format(style)))
        except Exception:
            return sublime.Html(
                mdpopups.md2html(self.view, DEF_COLORMOD.format(style)))
예제 #6
0
    def preview(self, text):
        """Preview."""

        style = self.get_html_style()

        try:
            colors = evaluate(text)

            html = ""
            for color in colors:
                srgb = Color(color).convert("srgb")
                preview_border = self.default_border
                message = ""
                color_string = ""
                if not srgb.in_gamut():
                    srgb.fit("srgb")
                    message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
                    color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(srgb.to_string())
                color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
                preview = srgb.to_string(**util.HEX_NA)
                preview_alpha = srgb.to_string(**util.HEX)
                preview_border = self.default_border

                height = self.height * 3
                width = self.width * 3
                check_size = self.check_size(height, scale=8)

                html += PREVIEW_IMG.format(
                    mdpopups.color_box(
                        [
                            preview,
                            preview_alpha
                        ], preview_border, border_size=1, height=height, width=width, check_size=check_size
                    ),
                    message,
                    color_string
                )
            if html:
                return sublime.Html(style + html)
            else:
                return sublime.Html(mdpopups.md2html(self.view, DEF_EDIT.format(style)))
        except Exception:
            return sublime.Html(mdpopups.md2html(self.view, DEF_EDIT.format(style)))
예제 #7
0
    def preview(self, new_alias):
        if not new_alias:
            new_alias = basename(self.path)

        if new_alias != self.alias:
            hint = f"Change display name from <u>{self.alias}</u> to <u>{new_alias}</u>"
        else:
            hint = f"Display name is <u>{self.alias}</u>"

        return sublime.Html(f"{hint}<br><br><i>{self.path}</i>")
    def preview(value):
        if not value:
            return ""

        # Just the first 10 lines
        content = ""
        for line in value.splitlines()[:11]:
            content += line + "<br />"

        preview_content = sublime.Html(content)
        return preview_content
    def preview(self, text):
        abbr = text.strip()
        snippet = None
        if abbr:
            try:
                result = emmet.expand(abbr, self.options)
                snippet = preview.format_snippet(result)
            except:
                snippet = '<div class="error">Invalid abbreviation</div>'

        if snippet:
            return sublime.Html(popup_content(snippet))
예제 #10
0
 def preview(desc, value):
     items = [
         'allman', 'gnu', 'horstmann', 'k_and_r', 'lisp', 'pico', 'ratliff',
         'whitesmiths'
     ]
     if value not in items:
         return None
     v = sublime.active_window().active_view()
     lsl_code_block = ResourcePath('{}/{}.lsl'.format(
         RESPATH_STYLES, value)
                                   # TODO: f'{RESPATH_STYLES}/{value}.lsl'
                                   ).read_text()
     lsl_code_block = '```lsl\n{}\n```'.format(lsl_code_block)
     # TODO: lsl_code_block = f'```lsl\n{lsl_code_block}\n```'
     return sublime.Html(mdpopups.md2html(v, lsl_code_block))
예제 #11
0
    def preview(self, pattern):
        try:
            make_filter_fn(pattern)
        except re.error as e:
            exc_str = str(e)
            hint_msg = PATTERN_ERROR_HINT.format(exc_str[0].upper() +
                                                 exc_str[1:])
        else:
            # Work-around https://github.com/SublimeTextIssues/Core/issues/2884
            # Calling this from the worker doesn't crash at least but the UX
            # is bad. 1. It is too laggy, 2. `sample_one_error` will work on
            # wrong, outdated data set.
            sublime.set_timeout_async(partial(set_filter, pattern))

            sample_error = sample_one_error(self.window)
            hint_msg = (EXAMPLE_MATCH_HINT.format(
                sample_error.replace('<', '&lt;').replace('>', '&gt;'))
                        if sample_error else NO_MATCH_HINT)

        return sublime.Html(HELP_MESSAGE.format(hint=hint_msg))
예제 #12
0
    def preview(self, text: str):
        abbr = text.strip()
        snippet = None

        undo_preview(self.view)

        if abbr:
            try:
                result = emmet.expand(abbr, self.options)
                if self.instant_preview:
                    self.view.run_command(
                        'emmet_wrap_with_abbreviation_preview', {
                            'region': (self.region.begin(), self.region.end()),
                            'result': result
                        })
            except:
                snippet = '<div class="error">Invalid abbreviation</div>'

        if snippet:
            return sublime.Html(popup_content(snippet))

        return None
예제 #13
0
		def preview(self, text):
			if text:
				path, file = os.path.split(text)
				return sublime.Html("{}<br>{}<br><i>{}</i>".format(path, file, "----"))
			else:
				return sublime.Html("No snippets found.<br><i>Either no snippet are available or none match the set filter</i>")
예제 #14
0
		def preview(self, text):
			try:
				return sublime.Html("Result: <i>{}</i>".format(str(castStringAsDict(text))))
			except:
				return "--ERROR--"
예제 #15
0
 def preview(self, value):
     return sublime.Html("<strong>{}</strong>: <em>{}</em>".format(
         self.names.get(value, "unknown"),
         self.descs.get(value, "unknown")
     ))
예제 #16
0
 def preview(self, text: str) -> sublime.Html:
     return sublime.Html(
         f"<b>{text[:2]}</b> / <i>{text[2:4]}</i> / <u>{text[4:6]}</u> / {text[6:]}"
         + '<a href="https://google.com">Link to Google</a>' +
         '<br><span style="color:red">Here is a new line</span>')
예제 #17
0
 def preview(self, value):
     return sublime.Html("<strong>{}</strong>: <em>{}</em>".format(
         value.split("/")[1], os.path.basename(value)))
예제 #18
0
 def preview(self, value):
     return sublime.Html("<i>{}</i>".format(value)) if value else None