diff options
-rwxr-xr-x | ranger.py | 17 | ||||
-rw-r--r-- | ranger/conf/colorschemes/__init__.py | 0 | ||||
-rw-r--r-- | ranger/conf/colorschemes/snow.py | 5 | ||||
-rw-r--r-- | ranger/gui/color.py | 26 | ||||
-rw-r--r-- | ranger/gui/colorscheme.py | 54 | ||||
-rw-r--r-- | ranger/gui/defaultui.py | 10 | ||||
-rw-r--r-- | ranger/gui/ui.py | 3 | ||||
-rw-r--r-- | ranger/gui/wdisplay.py | 5 | ||||
-rw-r--r-- | ranger/gui/widget.py | 17 |
9 files changed, 83 insertions, 54 deletions
diff --git a/ranger.py b/ranger.py index 9e8dbd70..b44fad46 100755 --- a/ranger.py +++ b/ranger.py @@ -20,6 +20,7 @@ from ranger.environment import Environment from ranger.command import CommandList from ranger.conf import keys, options from ranger.gui.defaultui import DefaultUI as UI +from ranger.conf.colorschemes.snow import Snow as ColorScheme import sys, os, locale @@ -41,22 +42,26 @@ locale.setlocale(locale.LC_ALL, 'en_US.utf8') try: path = os.path.abspath('.') opt = options.dummy() + env = Environment(opt) commandlist = CommandList() + colorscheme = ColorScheme() keys.initialize_commands(commandlist) - my_ui = UI(env, commandlist) + my_ui = UI(env, commandlist, colorscheme) my_fm = FM(env) my_fm.feed(path, my_ui) my_fm.run() -except BaseException as original_error: - try: my_ui.exit() - except: pass - - raise original_error +#except BaseException as original_error: +# try: my_ui.exit() +# except: pass +# +# raise original_error finally: + try: my_ui.exit() + except: pass if cd_after_exit: try: sys.__stderr__.write(env.pwd.path) except: pass diff --git a/ranger/conf/colorschemes/__init__.py b/ranger/conf/colorschemes/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/ranger/conf/colorschemes/__init__.py diff --git a/ranger/conf/colorschemes/snow.py b/ranger/conf/colorschemes/snow.py new file mode 100644 index 00000000..52f5dbb4 --- /dev/null +++ b/ranger/conf/colorschemes/snow.py @@ -0,0 +1,5 @@ +from ranger.gui.colorscheme import ColorScheme + +class Snow(ColorScheme): + def use(self, context): + return 1, 0, 0 diff --git a/ranger/gui/color.py b/ranger/gui/color.py deleted file mode 100644 index 5701c0ee..00000000 --- a/ranger/gui/color.py +++ /dev/null @@ -1,26 +0,0 @@ -#import curses - -color_pairs = {10: 0} - - -#class ColorScheme(): -# def isdir - - -#def get_color(fg, bg): -# c = bg+2 + 9*(fg + 2) -# try: -# return color_pairs[c] -# except KeyError: -# size = len(color_pairs) -# curses.init_pair(size, curses.COLOR_RED, curses.COLOR_WHITE) -# color_pairs[c] = size -# return color_pairs[c] -# -#def color(fg = -1, bg = -1, attribute = 0): -# pass -## prin -# curses.attrset(attribute | curses.color_pair(get_color(fg, bg))) - -#color(-1, -1) -#print(color_pairs) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py new file mode 100644 index 00000000..f410983f --- /dev/null +++ b/ranger/gui/colorscheme.py @@ -0,0 +1,54 @@ + +TUPLE_KEYS = ['wdisplay', 'wstatusbar', 'wtitlebar', 'wconsole', 'folder', 'executable', 'media', 'link', 'broken', 'selected'] + +COLOR_PAIRS = {10: 0} + +def get_color(fg, bg): + import curses + + c = bg+2 + 9*(fg + 2) + + if c not in COLOR_PAIRS: + size = len(COLOR_PAIRS) + curses.init_pair(size, fg, bg) + COLOR_PAIRS[c] = size + + return COLOR_PAIRS[c] + + +class ColorSchemeContext(object): + def __init__(self, dictionary): + object.__init__(self) + + self.__tuple__ = None + for key in TUPLE_KEYS: + if key in dictionary: + self.__dict__[key] = dictionary[key] + else: + self.__dict__[key] = False + + def to_tuple(self): + d = self.__dict__ + + if '__tuple__' is None: + self.__tuple__ = tuple(d[key] for key in TUPLE_KEYS) + + return self.__tuple__ + +class ColorScheme(): + def __init__(self): + self.cache = {} + + def get(self, **keywords): + con = ColorSchemeContext(keywords) + tup = con.to_tuple() + try: + return self.cache[tup] + except KeyError: + color = self.use(con) + self.cache[tup] = color + return color + + def use(self, context): + return -1, -1, 0 + diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py index 4d4f6d44..419d8a4f 100644 --- a/ranger/gui/defaultui.py +++ b/ranger/gui/defaultui.py @@ -6,14 +6,14 @@ RATIO = ( 0.15, 0.15, 0.4, 0.3 ) class DefaultUI(SuperClass): def setup(self): - self.titlebar = WTitleBar(self.win) + self.titlebar = WTitleBar(self.win, self.colorscheme) self.add_widget(self.titlebar) self.displays = [ - WDisplay(self.win, -2), - WDisplay(self.win, -1), - WDisplay(self.win, 0), - WDisplay(self.win, 1) ] + WDisplay(self.win, self.colorscheme, -2), + WDisplay(self.win, self.colorscheme, -1), + WDisplay(self.win, self.colorscheme, 0), + WDisplay(self.win, self.colorscheme, 1) ] self.displays[2].display_infostring = True self.displays[2].main_display = True for disp in self.displays: diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 2abf8939..6bcfc7fe 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -1,9 +1,10 @@ import curses from ranger.api import log class UI(): - def __init__(self, env, commandlist): + def __init__(self, env, commandlist, colorscheme): self.env = env self.commandlist = commandlist + self.colorscheme = colorscheme self.widgets = [] self.win = curses.initscr() diff --git a/ranger/gui/wdisplay.py b/ranger/gui/wdisplay.py index 95014d51..d8d70bf3 100644 --- a/ranger/gui/wdisplay.py +++ b/ranger/gui/wdisplay.py @@ -1,11 +1,10 @@ from ranger.gui.color import color_pairs from ranger.gui.widget import Widget as SuperClass import curses -#from ranger.color import color class WDisplay(SuperClass): - def __init__(self, win, level): - SuperClass.__init__(self,win) + def __init__(self, win, colorscheme, level): + SuperClass.__init__(self, win, colorscheme) self.level = level self.main_display = False self.display_infostring = False diff --git a/ranger/gui/widget.py b/ranger/gui/widget.py index cb5fdc1f..9c64cc1a 100644 --- a/ranger/gui/widget.py +++ b/ranger/gui/widget.py @@ -1,25 +1,16 @@ import curses -from ranger.gui.color import color_pairs +from ranger.gui.colorscheme import get_color class OutOfBoundsException(Exception): pass class Widget(): - def __init__(self, win): + def __init__(self, win, colorscheme): self.win = win + self.colorscheme = colorscheme self.setdim(0, 0, 0, 0) - def get_color(self, fg, bg): - c = bg+2 + 9*(fg + 2) - try: - return color_pairs[c] - except KeyError: - size = len(color_pairs) - curses.init_pair(size, fg, bg) - color_pairs[c] = size - return color_pairs[c] - def color(self, fg = -1, bg = -1, attr = 0): - self.win.attrset(attr | curses.color_pair(self.get_color(fg, bg))) + self.win.attrset(attr | curses.color_pair(get_color(fg, bg))) def setdim(self, y, x, hei=None, wid=None): maxy, maxx = self.win.getmaxyx() |