diff options
author | hut <hut@lavabit.com> | 2011-10-01 01:29:22 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-10-01 01:29:22 +0200 |
commit | c69ac7ec3f9b65750bccb6da3963e5615a07dc70 (patch) | |
tree | 5e3692161339f431585345bee13f4f0097cb217a | |
parent | 04f0e96ff0a0e234b638e1567baccaacf8e443b5 (diff) | |
download | ranger-c69ac7ec3f9b65750bccb6da3963e5615a07dc70.tar.gz |
gui.widgets.browserview: draw hints for keychains
-rw-r--r-- | ranger/core/actions.py | 3 | ||||
-rw-r--r-- | ranger/ext/keybinding_parser.py | 1 | ||||
-rw-r--r-- | ranger/gui/ui.py | 1 | ||||
-rw-r--r-- | ranger/gui/widgets/browserview.py | 31 |
4 files changed, 33 insertions, 3 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 6b879428..1904082e 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -334,9 +334,6 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): return self.execute_file(file, app = 'editor') - def hint(self, text): - self.ui.hint(text) - def toggle_option(self, string): """Toggle a boolean option named <string>""" if isinstance(self.env.settings[string], bool): diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py index b888032e..4e590283 100644 --- a/ranger/ext/keybinding_parser.py +++ b/ranger/ext/keybinding_parser.py @@ -81,6 +81,7 @@ ANYKEY = 9002 PASSIVE_ACTION = 9003 ALT_KEY = 9004 QUANT_KEY = 9005 +HINT_KEY = 9006 very_special_keys = { 'dir': DIRKEY, diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 89493618..28620882 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -147,6 +147,7 @@ class UI(DisplayableContainer): keybuffer.add(key) self.fm.hide_bookmarks() + self.browser.draw_hints = not keybuffer.finished_parsing if keybuffer.result is not None: try: diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py index 09944108..5acc322c 100644 --- a/ranger/gui/widgets/browserview.py +++ b/ranger/gui/widgets/browserview.py @@ -29,6 +29,7 @@ class BrowserView(Widget, DisplayableContainer): stretch_ratios = None need_clear = False old_collapse = False + draw_hints = False def __init__(self, win, ratios, preview = True): DisplayableContainer.__init__(self, win) @@ -102,6 +103,8 @@ class BrowserView(Widget, DisplayableContainer): DisplayableContainer.draw(self) if self.settings.draw_borders: self._draw_borders() + if self.draw_hints: + self._draw_hints() def finalize(self): if self.pager.visible: @@ -196,6 +199,34 @@ class BrowserView(Widget, DisplayableContainer): self.addch(0, right_end, curses.ACS_URCORNER) self.addch(self.hei - 1, right_end, curses.ACS_LRCORNER) + def _draw_hints(self): + self.need_clear = True + hints = [] + for k, v in self.fm.env.keybuffer.pointer.items(): + try: k = chr(k) + except: k = str(k) + if isinstance(v, dict): + text = '...' + else: + text = v + if text.startswith('hint') or text.startswith('chain hint'): + continue + hints.append((k, text)) + hints.sort(key=lambda t: t[1]) + + hei = min(self.hei - 1, len(hints)) + ystart = self.hei - hei + self.addnstr(ystart - 1, 0, "key command".ljust(self.wid), + self.wid) + self.win.chgat(ystart - 1, 0, curses.A_UNDERLINE) + whitespace = " " * self.wid + i = ystart + for key, cmd in hints: + string = " " + key.ljust(11) + " " + cmd + self.addstr(i, 0, whitespace) + self.addnstr(i, 0, string, self.wid) + i += 1 + def _collapse(self): # Should the last column be cut off? (Because there is no preview) if not self.settings.collapse_preview or not self.preview \ |