Exemple #1
0
def changeset(style):
    target_style = sublime.ui_info(
    )["system"]["style"] if style == "auto" else style
    inverse_style = "dark" if target_style == "light" else "light"

    style_settings = dict(dark=dict(), light=dict(), current=dict())
    for key, value in settings().to_dict().items():
        for mode in ["dark", "light"]:
            prefix = mode + "_"
            if key.startswith(prefix):
                key = key[len(prefix):]
                style_settings[mode][key] = value
                style_settings["current"][key] = settings().get(key)
                break

    changes = dict()
    for key, current_value in style_settings["current"].items():
        if key in style_settings[target_style]:
            actual_value = style_settings[target_style][key]
            if style == "auto" and key in ["theme", "color_scheme"]:
                actual_value = "auto"
            if current_value != actual_value:
                changes[key] = actual_value
        elif key in style_settings[inverse_style]:
            default_value = defaults()[key]
            if current_value != default_value:
                changes[key] = defaults()[key]

    return changes
    def run(self):
        settings = sublime.load_settings('Preferences.sublime-settings')
        theme_name = settings.get('theme', DEFAULT_THEME)

        if theme_name != 'auto':
            self.open_theme(theme_name)
        else:
            choices = [
                sublime.QuickPanelItem(
                    setting,
                    details=settings.get(setting, DEFAULT_THEME),
                    kind=KIND_THEME,
                ) for setting in ('dark_theme', 'light_theme')
            ]

            current_os_mode = sublime.ui_info()['system']['style']
            selected_index = -1
            for idx, choice in enumerate(choices):
                if choice.trigger.startswith(current_os_mode):
                    choice.annotation = 'Active'
                    selected_index = idx

            def on_done(i):
                if i >= 0:
                    self.open_theme(choices[i].details)

            self.window.show_quick_panel(
                choices,
                on_done,
                selected_index=selected_index,
                placeholder="Choose a theme to edit ...")
Exemple #3
0
    def run(self):
        theme = sublime.ui_info().get('theme', {}).get('resolved_value')
        if theme is None:
            theme = DEFAULT_THEME

        if '/' not in theme:
            possible_paths = sublime.find_resources(theme)
            default_path = 'Packages/Theme - Default/' + theme
            if default_path in possible_paths or len(possible_paths) == 0:
                theme = default_path
            else:
                theme = possible_paths[0]

        # edit_settings only works with ${packages}-based paths
        if theme.startswith('Packages/'):
            theme = '${packages}' + theme[8:]

        self.window.run_command(
            'edit_settings', {
                "base_file":
                theme,
                "default":
                "// Documentation at https://www.sublimetext.com/docs/themes.html\n"
                "{\n"
                "\t\"variables\":\n"
                "\t{\n"
                "\t},\n"
                "\t\"rules\":\n"
                "\t[\n"
                "\t\t$0\n"
                "\t]\n"
                "}\n"
            })
Exemple #4
0
    def run(self):
        view = self.window.active_view()
        if not view:
            return

        scheme_path = self.get_scheme_path(view, 'color_scheme')
        if scheme_path != 'auto':
            self.open_scheme(scheme_path)
        else:
            paths = [(setting, self.get_scheme_path(view, setting))
                     for setting in ('dark_color_scheme', 'light_color_scheme')
                     ]
            current_os_mode = sublime.ui_info()['system']['style']
            choices = [
                sublime.QuickPanelItem(setting,
                                       details=str(path),
                                       kind=KIND_SCHEME)
                for setting, path in paths
            ]

            selected_index = -1
            for idx, choice in enumerate(choices):
                if choice.trigger.startswith(current_os_mode):
                    choice.annotation = 'Active'
                    selected_index = idx

            def on_done(i):
                if i >= 0:
                    self.open_scheme(paths[i][1])

            self.window.show_quick_panel(
                choices,
                on_done,
                selected_index=selected_index,
                placeholder='Choose a color scheme to edit ...')
Exemple #5
0
    def run(self):
        color_scheme = sublime.ui_info().get('color_scheme',
                                             {}).get('resolved_value')
        if color_scheme is None:
            color_scheme = DEFAULT_CS

        if '/' not in color_scheme:
            possible_paths = sublime.find_resources(color_scheme)
            default_path = 'Packages/Color Scheme - Default/' + color_scheme
            if default_path in possible_paths or len(possible_paths) == 0:
                color_scheme = default_path
            else:
                color_scheme = possible_paths[0]

        # Ensure we always create overrides with the .sublime-color-scheme ext
        user_package_path = os.path.join(sublime.packages_path(), 'User')
        color_scheme_file_name = os.path.basename(color_scheme)
        base_name, ext = os.path.splitext(color_scheme_file_name)
        if ext in {'.tmTheme', '.hidden-tmTheme', '.hidden-color-scheme'}:
            color_scheme_file_name = base_name + '.sublime-color-scheme'
        user_file = os.path.join(user_package_path, color_scheme_file_name)

        # edit_settings only works with ${packages}-based paths
        if color_scheme.startswith('Packages/'):
            color_scheme = '${packages}' + color_scheme[8:]

        self.window.run_command(
            'edit_settings', {
                "base_file":
                color_scheme,
                'user_file':
                user_file,
                "default":
                "// Documentation at https://www.sublimetext.com/docs/color_schemes.html\n"
                "{\n"
                "\t\"variables\":\n"
                "\t{\n"
                "\t},\n"
                "\t\"globals\":\n"
                "\t{\n"
                "\t},\n"
                "\t\"rules\":\n"
                "\t[\n"
                "\t\t$0\n"
                "\t]\n"
                "}\n"
            })
Exemple #6
0
    def run(self, theme=None, remove=False, force=False):
        settings = sublime.load_settings("Terminus.sublime-settings")

        if not theme:
            theme = settings.get("theme", "default")

        if sublime.version() < "4096" and theme == "adaptive":
            theme = "default"

        if theme == "user":
            variables = settings.get("user_theme_colors", {})

            if sublime.version() >= "4096":
                current_style = sublime.ui_info()['theme']['style']
                style_variables = settings.get("user_{}_theme_colors".format(current_style), None)

                if isinstance(style_variables, dict):
                    variables = dict(variables, **style_variables)

            for key, value in list(variables.items()):
                if key.isdigit():
                    variables[ANSI_COLORS[int(key)]] = value
                    del variables[key]

        elif theme == "default" or theme == "classic":
            variables = {}
        elif theme == "adaptive":
            palette = sublime.ui_info()["color_scheme"]["palette"]
            gray = "#888888"
            window = sublime.active_window()
            if window:
                _panel = "terminus_color_scheme"
                view = window.create_output_panel(_panel, True)
                comment_foreground = view.style_for_scope("comment")["foreground"]
                r = int(comment_foreground[1:3], 16)
                g = int(comment_foreground[3:5], 16)
                b = int(comment_foreground[5:7], 16)
                _, _, s = rgb_to_hls(r/255, g/255, b/255)
                if s < 0.2:
                    gray = comment_foreground
                window.destroy_output_panel(_panel)
            light_color_template = "color({} l(+ 15%))"
            variables = {
                "background": palette["background"],
                "foreground": palette["foreground"],
                "black": "#000000",
                "red": palette["redish"],
                "green": palette["greenish"],
                "brown": palette["yellowish"],
                "blue": palette["bluish"],
                "magenta": palette["pinkish"],
                "cyan": palette["cyanish"],
                "white": gray,
                "light_black": light_color_template.format(gray),
                "light_red": light_color_template.format(palette["redish"]),
                "light_green": light_color_template.format(palette["greenish"]),
                "light_brown": light_color_template.format(palette["yellowish"]),
                "light_blue": light_color_template.format(palette["bluish"]),
                "light_magenta": light_color_template.format(palette["pinkish"]),
                "light_cyan": light_color_template.format(palette["cyanish"]),
                "light_white": "#ffffff"
            }
        else:
            content = sublime.load_resource("Packages/Terminus/themes/{}.json".format(theme))
            theme_data = sublime.decode_value(content)
            variables = theme_data["theme_colors"]

        path = os.path.join(
            sublime.packages_path(),
            "User",
            "Terminus",
            "Terminus.hidden-color-scheme"
        )

        path256 = os.path.join(
            sublime.packages_path(),
            "User",
            "Terminus.hidden-color-scheme"
        )

        if remove:
            if os.path.isfile(path):
                os.unlink(path)
                print("Theme removed: {}".format(path))
            if os.path.isfile(path256):
                os.unlink(path256)
                print("Theme removed: {}".format(path256))
            sublime.status_message("Theme {} removed".format(theme))
        else:
            if settings.get("256color", False):
                if force or not os.path.isfile(path256):
                    generate_theme_file(
                        path256, ansi_scopes=True, color256_scopes=True, pretty=False)
                    print("Theme {} generated: {}".format(theme, path256))
            else:
                if os.path.isfile(path256):
                    os.unlink(path256)

            generate_theme_file(path, variables=variables, ansi_scopes=False, color256_scopes=False)
            print("Theme {} generated: {}".format(theme, path))

            sublime.status_message("Theme generated")