diff options
author | hut <hut@lepus.uberspace.de> | 2015-03-18 22:35:58 +0100 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2015-03-18 22:44:52 +0100 |
commit | bc79568d49652375c08a5c8d58262b1ef03d44e7 (patch) | |
tree | 23ce5566e1294d423accd9493a946f145a214840 | |
parent | a5a84e52ec20867d114e0450477477be19b8227c (diff) | |
download | ranger-bc79568d49652375c08a5c8d58262b1ef03d44e7.tar.gz |
config/commands.py: refractored randynobx's patch
1. moved colorscheme-finding code from fsobject.py to colorscheme.py 2. use set rather than dict to uniquely collect colorschemes
-rw-r--r-- | ranger/config/commands.py | 9 | ||||
-rw-r--r-- | ranger/container/fsobject.py | 20 | ||||
-rw-r--r-- | ranger/gui/colorscheme.py | 16 |
3 files changed, 22 insertions, 23 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index e129aac4..581ea090 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -336,6 +336,7 @@ class set_(Command): self.fm.set_option_from_string(name, value) def tab(self): + from ranger.gui.colorscheme import get_all_colorschemes name, value, name_done = self.parse_setting_line() settings = self.fm.settings if not name: @@ -346,8 +347,8 @@ class set_(Command): if not value: # Cycle through colorschemes when name, but no value is specified if name == "colorscheme": - return (self.firstpart + colorscheme - for colorscheme in self.fm.thisfile.colorscheme_dict.keys()) + return (self.firstpart + colorscheme for colorscheme \ + in get_all_colorschemes()) return self.firstpart + str(settings[name]) if bool in settings.types_of(name): if 'true'.startswith(value.lower()): @@ -356,8 +357,8 @@ class set_(Command): return self.firstpart + 'False' # Tab complete colorscheme values if incomplete value is present if name == "colorscheme": - return (self.firstpart + colorscheme for colorscheme in self.fm.thisfile.colorscheme_dict.keys() \ - if colorscheme.startswith(value)) + return (self.firstpart + colorscheme for colorscheme \ + in get_all_colorschemes() if colorscheme.startswith(value)) class setlocal(set_): diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index 585bbb26..6cdaa727 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -14,8 +14,8 @@ BAD_INFO = '?' import re from grp import getgrgid -from os import lstat, stat, getcwd, listdir -from os.path import abspath, basename, dirname, realpath, splitext, extsep, relpath, expanduser, isdir +from os import lstat, stat, getcwd +from os.path import abspath, basename, dirname, realpath, splitext, extsep, relpath from pwd import getpwuid from ranger.core.linemode import * from ranger.core.shared import FileManagerAware, SettingsAware @@ -23,7 +23,6 @@ from ranger.ext.shell_escape import shell_escape from ranger.ext.spawn import spawn from ranger.ext.lazy_property import lazy_property from ranger.ext.human_readable import human_readable -from ranger import RANGERDIR,CONFDIR if hasattr(str, 'maketrans'): maketrans = str.maketrans @@ -90,21 +89,6 @@ class FileSystemObject(FileManagerAware, SettingsAware): [DefaultLinemode, TitleLinemode, PermissionsLinemode] ) - _colorscheme = "default" - colorschemes = [] - # Load colorscheme names from main ranger/colorschemes dir - for item in listdir(RANGERDIR + '/colorschemes'): - if not item.startswith('__'): - colorschemes.append(item.rsplit('.', 1)[0]) - # Load colorscheme names from ~/.config/ranger/colorschemes if dir exists - if isdir(expanduser(CONFDIR + '/colorschemes')): - for item in listdir(expanduser(CONFDIR + '/colorschemes')): - if not item.startswith('__'): - colorschemes.append(item.rsplit('.', 1)[0]) - colorscheme_dict = dict( - (colorscheme, colorscheme + '.py') for colorscheme in colorschemes - ) - def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel_to=None): if not path_is_abs: path = abspath(path) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 580621e1..d281c43a 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -24,7 +24,7 @@ Define which colorscheme in your settings (e.g. ~/.config/ranger/rc.conf): set colorscheme yourschemename """ -import os +import os.path from curses import color_pair import ranger @@ -131,3 +131,17 @@ def _colorscheme_name_to_class(signal): break else: raise Exception("The module contains no valid colorscheme!") + +def get_all_colorschemes(): + colorschemes = set() + # Load colorscheme names from main ranger/colorschemes dir + for item in os.listdir(ranger.RANGERDIR + '/colorschemes'): + if not item.startswith('__'): + colorschemes.add(item.rsplit('.', 1)[0]) + # Load colorscheme names from ~/.config/ranger/colorschemes if dir exists + if os.path.isdir(os.path.expanduser(ranger.CONFDIR + '/colorschemes')): + for item in os.listdir(os.path.expanduser( + ranger.CONFDIR + '/colorschemes')): + if not item.startswith('__'): + colorschemes.add(item.rsplit('.', 1)[0]) + return list(sorted(colorschemes)) |