diff options
author | hut <hut@lavabit.com> | 2009-12-29 21:27:46 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-12-29 21:27:46 +0100 |
commit | 5715becad1ecc186408883518fa516392ebf6d55 (patch) | |
tree | 3de750d52f336cf9cc0f1b1dfa07a2acd30c2ed0 /ranger | |
parent | 836e9eae3bf074ec1f3db808b23526cdca7b1323 (diff) | |
download | ranger-5715becad1ecc186408883518fa516392ebf6d55.tar.gz |
F1 key (inside console) for viewing information about the command
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/actions.py | 22 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 5 | ||||
-rw-r--r-- | ranger/gui/defaultui.py | 7 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 11 | ||||
-rw-r--r-- | ranger/gui/widgets/pager.py | 10 |
5 files changed, 48 insertions, 7 deletions
diff --git a/ranger/actions.py b/ranger/actions.py index 3aef7d86..d85184a3 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -152,6 +152,28 @@ class Actions(EnvironmentAware, SettingsAware): """Handle mouse-buttons if one was pressed""" self.ui.handle_mouse() + def display_command_help(self, console_widget): + if not hasattr(self.ui, 'open_pager'): + return + + try: + command = console_widget._get_cmd_class() + except: + self.notify("Feature not available!", bad=True) + return + + if not command: + self.notify("Command not found!", bad=True) + return + + if not command.__doc__: + self.notify("Command has no docstring. Try using python without -OO", + bad=True) + return + + pager = self.ui.open_pager() + pager.set_source(command.__doc__.strip(), strip=True) + def display_file(self): if not hasattr(self.ui, 'open_embedded_pager'): return diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 6bce7289..958f3744 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -192,6 +192,7 @@ def initialize_console_commands(command_list): bind(ctrl('k'), wdg.delete_rest(1)) bind(ctrl('u'), wdg.delete_rest(-1)) bind(ctrl('y'), wdg.paste()) + bind(KEY_F1, lambda arg: arg.fm.display_command_help(arg.wdg)) # system functions system_functions(command_list) @@ -229,7 +230,9 @@ def initialize_process_manager_commands(command_list): command_list.rebuild_paths() def initialize_pager_commands(command_list): + bind, hint = make_abbreviations(command_list) initialize_embedded_pager_commands(command_list) + bind('q', 'i', ESC, KEY_F1, lambda arg: arg.fm.ui.close_pager()) def initialize_embedded_pager_commands(command_list): system_functions(command_list) @@ -240,7 +243,7 @@ def initialize_embedded_pager_commands(command_list): bind('gg', KEY_DOWN, nwrap.move(absolute=0)) bind('G', KEY_DOWN, nwrap.move(absolute=-1)) - bind('q', 'i', lambda arg: arg.fm.ui.close_embedded_pager()) + bind('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager()) bind('h', wdg.move_horizontal(relative=-4)) bind('l', wdg.move_horizontal(relative=4)) bind('Q', 'ZZ', fm.exit()) diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py index 462d394d..717bb925 100644 --- a/ranger/gui/defaultui.py +++ b/ranger/gui/defaultui.py @@ -1,6 +1,5 @@ RATIO = ( 3, 3, 12, 9 ) -from ranger import log from ranger.gui.ui import UI class DefaultUI(UI): @@ -61,14 +60,19 @@ class DefaultUI(UI): return self.notify.display(*a, **k) def close_pager(self): + if self.console.visible: + self.console.focused = True self.pager.visible = False self.pager.focused = False self.filelist_container.visible = True def open_pager(self): + if self.console.focused: + self.console.focused = False self.pager.visible = True self.pager.focused = True self.filelist_container.visible = False + return self.pager def open_embedded_pager(self): self.filelist_container.open_pager() @@ -86,6 +90,7 @@ class DefaultUI(UI): def close_console(self): self.console.visible = False self.status.visible = True + self.close_pager() def open_pman(self): self.filelist_container.visible = False diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index db92908b..22b9831d 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -245,17 +245,22 @@ class CommandConsole(ConsoleWithTab): Console.execute(self) def _get_cmd(self): + command_class = self._get_cmd_class() + if command_class: + return command_class(self.line, self.mode) + else: + return None + + def _get_cmd_class(self): try: command_name = self.line.split()[0] except IndexError: return None try: - command_class = commands.by_name[command_name] + return commands.by_name[command_name] except KeyError: return None - - return command_class(self.line, self.mode) def _get_tab(self): if ' ' in self.line: diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index c149f89a..1664cc4b 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -83,11 +83,14 @@ class Pager(Widget): cmd.execute_wrap(self) self.env.key_clear() - def set_source(self, source): + def set_source(self, source, strip=False): if self.source and self.source_is_stream: self.source.close() - if hasattr(source, '__getitem__'): + if isinstance(source, str): + self.source_is_stream = False + self.lines = source.split('\n') + elif hasattr(source, '__getitem__'): self.source_is_stream = False self.lines = source elif hasattr(source, 'readline'): @@ -98,6 +101,9 @@ class Pager(Widget): self.source_is_stream = False return False + if not self.source_is_stream and strip: + self.lines = map(lambda x: x.strip(), self.lines) + self.source = source return True |