Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make theme/color_scheme optional #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Terminus.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
// the name of the theme
// Terminus comes with a number of themes - select a predefined theme using
// `Terminus Utilities: Select Theme`.
// Setting this to "" prevents Terminus from specifying a color scheme
// for its views, falling back on the global default.
"theme": "default",

// change `theme` to "user" if you want to use customized theme
Expand Down
5 changes: 4 additions & 1 deletion terminus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .utils import shlex_split
from .utils import available_panel_name, rev_wcwidth, highlight_key
from .view import panel_window, panel_is_visible, view_is_visible
from .theme import get_theme


KEYS = [
Expand Down Expand Up @@ -626,7 +627,9 @@ def run(self, _, **kwargs):
view_settings.set("draw_indent_guides", False)
# view_settings.set("caret_style", "blink")
view_settings.set("scroll_past_end", True)
view_settings.set("color_scheme", "Terminus.hidden-color-scheme")

if get_theme(terminus_settings):
view_settings.set("color_scheme", "Terminus.hidden-color-scheme")

max_columns = terminus_settings.get("max_columns")
if max_columns:
Expand Down
21 changes: 15 additions & 6 deletions terminus/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def run(self, theme=None):
if not self.themefiles:
self.themefiles = list(self.get_theme_files())

if theme:
if theme not in ["default", "user"]:
if theme is not None:
if theme and theme not in ["default", "user"]:
if theme + ".json" not in self.themefiles:
raise IOError("Theme '{}' not found".format(theme))
settings = sublime.load_settings("Terminus.sublime-settings")
settings.set("theme", theme)
sublime.save_settings("Terminus.sublime-settings")

else:
self.themes = ["default", "user"] + \
self.themes = ["", "default", "user"] + \
sorted([f.replace(".json", "") for f in self.themefiles])
settings = sublime.load_settings("Terminus.sublime-settings")
self.original_theme = settings.get("theme", "default")
self.original_theme = get_theme(settings)
try:
selected_index = self.themes.index(self.original_theme)
except Exception:
Expand All @@ -57,7 +57,11 @@ def run(self, theme=None, remove=False, force=False):
settings = sublime.load_settings("Terminus.sublime-settings")

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

if not theme:
return

if theme == "user":
variables = settings.get("user_theme_colors", {})
for key, value in list(variables.items()):
Expand All @@ -67,6 +71,7 @@ def run(self, theme=None, remove=False, force=False):

elif theme == "default":
variables = {}

else:
content = sublime.load_resource("Packages/Terminus/themes/{}.json".format(theme))
theme_data = sublime.decode_value(content)
Expand Down Expand Up @@ -136,7 +141,7 @@ def plugin_loaded():
"Terminus.hidden-color-scheme"
)

if settings.get("theme", "default") != "default":
if get_theme(settings) != "default":
if (not os.path.isfile(path) or
(settings.get("256color", False) and not os.path.isfile(path256))):
sublime.set_timeout(
Expand All @@ -151,3 +156,7 @@ def plugin_loaded():
def plugin_unloaded():
settings = sublime.load_settings("Terminus.sublime-settings")
settings_on_change(settings, ["256color", "user_theme_colors", "theme"], clear=True)


def get_theme(settings):
return settings.get("theme", "default")