diff options
author | hut <hut@lavabit.com> | 2009-12-24 12:12:43 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-12-24 12:12:43 +0100 |
commit | a396b3a0a77fb13834c3ed2fe7bd3838a73c5c00 (patch) | |
tree | 9221263a6f857e0eb889f0ba3b0fa6bba9e9c021 /ranger | |
parent | 893dd6b4d301fcaccbc37a13746610a10149f0a1 (diff) | |
download | ranger-a396b3a0a77fb13834c3ed2fe7bd3838a73c5c00.tar.gz |
added hints for key-combinations
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/colorschemes/default.py | 4 | ||||
-rw-r--r-- | ranger/container/commandlist.py | 51 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 4 | ||||
-rw-r--r-- | ranger/gui/colorscheme.py | 1 | ||||
-rw-r--r-- | ranger/gui/defaultui.py | 5 | ||||
-rw-r--r-- | ranger/gui/ui.py | 15 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 1 | ||||
-rw-r--r-- | ranger/gui/widgets/statusbar.py | 31 |
8 files changed, 95 insertions, 17 deletions
diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py index 13a20db9..e3cdb766 100644 --- a/ranger/colorschemes/default.py +++ b/ranger/colorschemes/default.py @@ -79,4 +79,8 @@ class Default(ColorScheme): # attr |= bold # fg = white + if context.text: + if context.highlight: + attr |= reverse + return fg, bg, attr diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py index ab6f1102..d38116eb 100644 --- a/ranger/container/commandlist.py +++ b/ranger/container/commandlist.py @@ -1,6 +1,8 @@ class CommandList(object): - """CommandLists are dictionary-like objects which give you a command -for a given key combination. CommandLists must be filled before use.""" + """ + CommandLists are dictionary-like objects which give you a command + for a given key combination. CommandLists must be filled before use. + """ dummy_object = None dummies_in_paths = False @@ -16,11 +18,13 @@ for a given key combination. CommandLists must be filled before use.""" return self.paths[key] def rebuild_paths(self): - """Fill the path dictionary with dummie objects. -We need to know when to clear the keybuffer (when a wrong key is pressed) -and when to wait for the rest of the key combination. For "gg" we -will assign "g" to a dummy which tells the program to do the latter -and wait.""" + """ + Fill the path dictionary with dummie objects. + We need to know when to clear the keybuffer (when a wrong key is pressed) + and when to wait for the rest of the key combination. For "gg" we + will assign "g" to a dummy which tells the program to do the latter + and wait. + """ if self.dummies_in_paths: self.remove_dummies() @@ -51,7 +55,10 @@ and wait.""" return all def remove_dummies(self): - """remove dummie objects in case you have to rebuild a path dictionary which already contains dummie objects.""" + """ + Remove dummie objects in case you have to rebuild a path dictionary + which already contains dummie objects. + """ for k in tuple(paths.keys()): if paths[k] == self.dummy_object: del paths[k] self.dummies_in_paths = False @@ -80,6 +87,19 @@ and wait.""" for key in keys: self.paths[key] = cmd + def hint(self, text, *keys): + """create a Hint object and assign it to the given key combinations.""" + if len(keys) == 0: return + + keys = tuple(map(self._str_to_tuple, keys)) + + obj = Hint(text, keys) + + self.commandlist.append(obj) + for key in keys: + self.paths[key] = obj + + class Command(object): """Command objects store information about a command""" @@ -91,4 +111,19 @@ class Command(object): def execute(self, *args): """Execute the command""" + +# def __str__(self): +# return 'Cmd({0})'.format(str(self.keys)) + +class Hint(object): + """Hints display text without clearing the keybuffer""" + + keys = [] + text = '' + + def __init__(self, text, keys): + self.keys = keys + self.text = text +# def __str__(self): +# return 'Hint({0})'.format(str(self.keys)) diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index f40d97d9..68294b22 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -45,9 +45,13 @@ def initialize_commands(command_list): bind('cut', do('cut')) bind('p', do('paste')) + t_hint = "show_//h//idden //p//review_files //d//irectories_first //a//uto_load_preview //c//ollapse_preview" + command_list.hint(t_hint, 't') bind('th', do('toggle_boolean_option', 'show_hidden')) bind('tp', do('toggle_boolean_option', 'preview_files')) bind('td', do('toggle_boolean_option', 'directories_first')) + bind('ta', do('toggle_boolean_option', 'auto_load_preview')) + bind('tc', do('toggle_boolean_option', 'collapse_preview')) bind('cd', do('open_console', ':', 'cd ')) bind('f', do('open_console', '>', 'find ')) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 386c0f85..4fdcaad2 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -9,6 +9,7 @@ CONTEXT_KEYS = [ 'reset', 'error', 'space', 'permissions', 'owner', 'group', 'mtime', 'nlink', 'scroll', 'all', 'bot', 'top', 'percentage', 'marked', + 'text', 'highlight', 'keybuffer'] # colorscheme specification: diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py index ba3f79c9..2b1fa188 100644 --- a/ranger/gui/defaultui.py +++ b/ranger/gui/defaultui.py @@ -68,5 +68,8 @@ class DefaultUI(UI): self.titlebar.throbber = type(self.titlebar).throbber else: self.titlebar.throbber = string - + # self.win.addnstr(0, self.env.termsize[1]-1, string, 1) + + def hint(self, text=None): + self.status.override = text diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 8134231e..07c2de6f 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -105,6 +105,10 @@ class UI(DisplayableContainer): def handle_key(self, key): """Handles key input""" + + if hasattr(self, 'hint'): + self.hint() + self.env.key_append(key) if DisplayableContainer.press(self, key): @@ -121,11 +125,12 @@ class UI(DisplayableContainer): self.env.key_clear() return - if cmd == self.commandlist.dummy_object: - return - - cmd.execute(self.fm, self.env.keybuffer.number) - self.env.key_clear() + if hasattr(cmd, 'text'): + if hasattr(self, 'hint'): + self.hint(cmd.text) + elif hasattr(cmd, 'execute'): + cmd.execute(self.fm, self.env.keybuffer.number) + self.env.key_clear() def get_next_key(self): """Waits for key input and returns the pressed key""" diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 1512b763..ee80e639 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -20,6 +20,7 @@ class Console(Widget): original_line = None history = None histories = None + override = None def __init__(self, win): from ranger.container import CommandList, History diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 17a5348b..c3c5e74e 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -15,6 +15,7 @@ class StatusBar(Widget): owners = {} groups = {} timeformat = '%Y-%m-%d %H:%M' + override = None def __init__(self, win, filelist=None): Widget.__init__(self, win) @@ -26,9 +27,33 @@ class StatusBar(Widget): # each item in the returned array looks like: # [ list_with_color_tags, string ] # [ ['permissions', 'allowed'], '-rwxr-xr-x' ] - left = self._get_left_part() - right = self._get_right_part() - self._print_result(self._combine_parts(left, right)) + + if self.override and isinstance(self.override, str): + self._draw_message() + else: + left = self._get_left_part() + right = self._get_right_part() + self._print_result(self._combine_parts(left, right)) + + def _draw_message(self): + highlight = True + space_left = self.wid + starting_point = self.x + for string in self.override.split('//'): + highlight = not highlight + if highlight: + self.color('in_statusbar', 'text', 'highlight') + else: + self.color('in_statusbar', 'text') + + try: + self.win.addnstr(self.y, starting_point, string, space_left) + except: + break + space_left -= len(string) + starting_point += len(string) +# if starting_point >= self.wid: +# break def _get_left_part(self): part = [] |