diff options
author | hut <hut@lepus.uberspace.de> | 2016-01-11 00:34:34 +0100 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2016-01-11 00:34:34 +0100 |
commit | f250843305b823ad5bd5cb497ef1fdfbaa0c3408 (patch) | |
tree | 0f6ed979584543e2b9152ec4858ff7157d37d434 | |
parent | f9526c1f32c8ca7ea1d41735689a7ae8d6cf1958 (diff) |
new colorscheme implementation WIPnewcolor
-rw-r--r-- | ranger/config/commands.py | 29 | ||||
-rw-r--r-- | ranger/config/rc.conf | 61 | ||||
-rw-r--r-- | ranger/container/fsobject.py | 3 | ||||
-rw-r--r-- | ranger/container/settings.py | 1 | ||||
-rw-r--r-- | ranger/gui/context.py | 14 | ||||
-rw-r--r-- | ranger/gui/curses_shortcuts.py | 13 | ||||
-rw-r--r-- | ranger/gui/displayable.py | 4 | ||||
-rw-r--r-- | ranger/gui/ui.py | 34 | ||||
-rw-r--r-- | ranger/gui/widgets/browsercolumn.py | 8 |
9 files changed, 156 insertions, 11 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 40377547..823d96f5 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -101,6 +101,35 @@ class alias(Command): self.fm.commands.alias(self.arg(1), self.rest(2)) +class color(Command): + def execute(self): + from ranger.ext.colorscheme import ColorManager + tags = self.arg(1).split(".") + operator = self.arg(2) + colors = self.arg(3) + + if not tags or not operator or not colors: + self.fm.notify('Syntax: color <tags> = <colors>', bad=True) + + colors = colors.split(",") + + if len(colors) <= 2: + colors.extend([""] * (3 - len(colors))) + elif len(colors) > 3: + self.fm.notify('Syntax Error: need 1-3 color attributes, ' + 'supplied %d in %s' % (len(colors), self.arg(3)), bad=True) + + try: + colors[0] = ColorManager._parse_color(colors[0]) # foreground + colors[1] = ColorManager._parse_color(colors[1]) # background + colors[2] = ColorManager._parse_attribute(colors[2]) # attribs + except ValueError as e: + self.fm.notify(e) + else: + self.fm.ui.colors.define(tags, colors[0], colors[1], *colors[2]) + self.fm.ui.colorscheme_type = "new" + + class echo(Command): """:echo <text> diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index d719da20..42a6a04e 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -582,3 +582,64 @@ tmap <delete> eval -q fm.ui.taskview.task_remove() tmap <C-l> redraw_window tmap <ESC> taskview_close copytmap <ESC> q Q w <C-c> + + +color default = default,default,normal +color in_browser.selected = ,,reverse +color in_browser.empty = ,red +color in_browser.error = ,red +color in_browser.is_media = magenta +color in_browser.is_image = yellow +color in_browser.is_container = red +color in_browser.is_directory = blue,,+bold +#color browser.executable.!is_media.!is_container.!is_fifo.!is_socket = green,,+bold +color in_browser.is_socket = magenta,,+bold +color in_browser.is_fifo = yellow +color in_browser.is_device = yellow,,+bold +color in_browser.is_link = cyan +color in_browser.is_link.bad = magenta +#color browser.tag_marker.!selected = red,,+bold +color browser.tag_marker.!.! = red,,+bold +#color browser.cut.!selected = black,,+bold +#color browser.copied.!selected = black,,+bold +color in_browser.main_column.selected = ,,+bold +color in_browser.main_column.marked = yellow,,+bold + +color in_titlebar = ,,+bold +color in_titlebar.user = green +color in_titlebar.user.user_is_root = red +color in_titlebar.hostname = green +color in_titlebar.hostname.user_is_root = red +color in_titlebar.is_directory = blue +color in_titlebar.tab.activetab = ,green +#color in_titlebar.link.!brokenlink = cyan +color in_titlebar.link.brokenlink = magenta + +color statusbar.permissions.readable = cyan +#color statusbar.permissions.!readable = magenta +color statusbar.marked = ,yellow,+bold|+reverse +color statusbar.message.error = red,,bold +color statusbar.loaded = ,blue +color statusbar.vcsinfo = blue,,-bold +color statusbar.vcscommit = yellow,,-bold + +color text.highlight = ,,reverse + +color taskview.title = blue +color taskview.selected = ,,+reverse +color taskview.loaded.selected = blue +#color taskview.loaded.!selected = ,blue + +#color vcsfile.!selected = ,,-bold +#color vcsfile.!selected.vcs_conflict = red +#color vcsfile.!selected.vcs_unknown = red +#color vcsfile.!selected.vcs_staged = green +#color vcsfile.!selected.vcs_sync = green +#color vcsfile.!selected.vcs_ignored = default + +#color vcsremote.!selected = ,,-bold +#color vcsremote.!selected.vcs_sync = green +#color vcsremote.!selected.vcs_behind = red +#color vcsremote.!selected.vcs_ahead = blue +#color vcsremote.!selected.vcs_diverged = magenta +#color vcsremote.!selected.vcs_unknown = red diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index aa848b7a..094bc11a 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -203,7 +203,8 @@ class FileSystemObject(FileManagerAware, SettingsAware): self.container = self.extension in CONTAINER_EXTENSIONS keys = ('video', 'audio', 'image', 'media', 'document', 'container') - self._mimetype_tuple = tuple(key for key in keys if getattr(self, key)) + self._mimetype_tuple = tuple("type_" + key + for key in keys if getattr(self, key)) if self._mimetype == '': self._mimetype = None diff --git a/ranger/container/settings.py b/ranger/container/settings.py index db8ca45c..eed5c0d7 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -100,6 +100,7 @@ class Settings(SignalDispatcher, FileManagerAware): elif name == 'colorscheme': _colorscheme_name_to_class(signal) + self.fm.ui.colorscheme_type = "old" elif name == 'preview_script': if isinstance(value, str): diff --git a/ranger/gui/context.py b/ranger/gui/context.py index e5aef06c..dc3772a9 100644 --- a/ranger/gui/context.py +++ b/ranger/gui/context.py @@ -21,11 +21,25 @@ CONTEXT_KEYS = ['reset', 'error', 'badinfo', 'vcsconflict', 'vcschanged', 'vcsunknown', 'vcsignored', 'vcsstaged', 'vcssync', 'vcsbehind', 'vcsahead', 'vcsdiverged'] +CONVERSION_MAP = dict( + is_directory='directory', + is_image='image', + is_media='media', + is_socket='socket', + is_device='device', + is_video='video', + is_audio='image', + is_document='document', + is_container='container', +) + class Context(object): def __init__(self, keys): # set all given keys to True d = self.__dict__ for key in keys: + if key in CONVERSION_MAP: + key = CONVERSION_MAP[key] d[key] = True # set all keys to False diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py index e7573f17..b7625132 100644 --- a/ranger/gui/curses_shortcuts.py +++ b/ranger/gui/curses_shortcuts.py @@ -6,7 +6,7 @@ import _curses import sys from ranger.gui.color import get_color -from ranger.core.shared import SettingsAware +from ranger.core.shared import FileManagerAware REVERSE_ADDCH_ARGS = sys.version[0:5] == '3.4.0' @@ -14,7 +14,7 @@ def _fix_surrogates(args): return [isinstance(arg, str) and arg.encode('utf-8', 'surrogateescape') .decode('utf-8', 'replace') or arg for arg in args] -class CursesShortcuts(SettingsAware): +class CursesShortcuts(FileManagerAware): """This class defines shortcuts to faciliate operations with curses. color(*keys) -- sets the color associated with the keys from @@ -62,7 +62,7 @@ class CursesShortcuts(SettingsAware): def color(self, *keys): """Change the colors from now on.""" - attr = self.settings.colorscheme.get_attr(*keys) + attr = CursesShortcuts.get_color_attr(self, keys) try: self.win.attrset(attr) except _curses.error: @@ -70,7 +70,7 @@ class CursesShortcuts(SettingsAware): def color_at(self, y, x, wid, *keys): """Change the colors at the specified position""" - attr = self.settings.colorscheme.get_attr(*keys) + attr = CursesShortcuts.get_color_attr(self, keys) try: self.win.chgat(y, x, wid, attr) except _curses.error: @@ -85,3 +85,8 @@ class CursesShortcuts(SettingsAware): def color_reset(self): """Change the colors to the default colors""" CursesShortcuts.color(self, 'reset') + + def get_color_attr(self, tags): + if self.fm.ui.colorscheme_type == "new": + return self.fm.ui.colors.get_attr(*tags) + return self.fm.settings.colorscheme.get_attr(*tags) diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py index d3adfe50..617e1296 100644 --- a/ranger/gui/displayable.py +++ b/ranger/gui/displayable.py @@ -1,10 +1,10 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. -from ranger.core.shared import FileManagerAware +from ranger.core.shared import SettingsAware from ranger.gui.curses_shortcuts import CursesShortcuts -class Displayable(FileManagerAware, CursesShortcuts): +class Displayable(SettingsAware, CursesShortcuts): """Displayables are objects which are displayed on the screen. This is just the abstract class, defining basic operations diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 2eacbc4d..4cfd1c78 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -9,6 +9,30 @@ import _curses from .displayable import DisplayableContainer from .mouse_event import MouseEvent from ranger.ext.keybinding_parser import KeyBuffer, KeyMaps, ALT_KEY +from ranger.ext.colorscheme import ColorManager + +COLORSCHEME_TAGS = """ +default +reset error badinfo +in_browser in_statusbar in_titlebar in_console +in_pager in_taskview +directory file hostname +executable media link fifo socket device +video audio image media document container +selected empty main_column message background +good bad +space permissions owner group mtime nlink +scroll all bot top percentage filter +flat marked tagged tag_marker cut copied +title text highlight bars quotes tab loaded +keybuffer +infostring +vcsfile vcsremote vcsinfo vcscommit +vcsconflict vcschanged vcsunknown vcsignored +vcsstaged vcssync vcsbehind vcsahead vcsdiverged +""" + +COLORSCHEME_TAGS += "help_markup seperator key special border" # COMPAT MOUSEMASK = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION @@ -40,6 +64,16 @@ class UI(DisplayableContainer): def __init__(self, env=None, fm=None): self.keybuffer = KeyBuffer() self.keymaps = KeyMaps(self.keybuffer) + self.colors = ColorManager(logger=lambda message: + self.fm.notify(message, bad=True)) + self.colors.allowed_tags |= set(COLORSCHEME_TAGS.split()) + + # This attribute can be either "old" or "new", with "old" referring + # to the old python-class-based ranger.gui.colorscheme module and + # "new" referring to the `:color <tags> = <colors>` command-based + # ranger.ext.colorscheme module. Whenever either `:colorscheme` or + # `:set colorscheme = ...` is used, it's set to "new" or "old" resp. + self.colorscheme_type = "new" if fm is not None: self.fm = fm diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 24bf6408..9b27a284 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -261,7 +261,7 @@ class BrowserColumn(Pager): predisplay = predisplay_left + predisplay_right for txt, color in predisplay: - attr = self.settings.colorscheme.get_attr(*(this_color + color)) + attr = self.get_color_attr(this_color + color) display_data.append([txt, attr]) return display_data @@ -276,7 +276,7 @@ class BrowserColumn(Pager): if self.level > 0 and not self.settings.preview_directories: return - base_color = ['in_browser'] + base_color = ['in_browser', 'file'] self.win.move(0, 0) @@ -391,9 +391,9 @@ class BrowserColumn(Pager): if self.fm.tags and drawn.realpath in self.fm.tags: this_color.append('tagged') if drawn.is_directory: - this_color.append('directory') + this_color.append('is_directory') else: - this_color.append('file') + this_color.append('is_file') if drawn.stat: mode = drawn.stat.st_mode |