def execute_console(self, string='', wildcards=[], quantifier=None): """:execute_console [string] Execute a command for the console """ command_name = string.lstrip().split()[0] cmd_class = self.commands.get_command(command_name, abbrev=False) if cmd_class is None: self.notify("Command not found: `%s'" % command_name, bad=True) return cmd = cmd_class(string) if cmd.resolve_macros and _MacroTemplate.delimiter in string: macros = dict(('any%d'%i, key_to_string(char)) \ for i, char in enumerate(wildcards)) if 'any0' in macros: macros['any'] = macros['any0'] try: string = self.substitute_macros(string, additional=macros, escape=cmd.escape_macros_for_shell) except ValueError as e: if ranger.arg.debug: raise else: return self.notify(e) try: cmd_class(string, quantifier=quantifier).execute() except Exception as e: if ranger.arg.debug: raise else: self.notify(e)
def _draw_hints(self): self.need_clear = True hints = [] for k, v in self.fm.env.keybuffer.pointer.items(): k = key_to_string(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) try: self.win.chgat(ystart - 1, 0, curses.A_UNDERLINE) except: pass 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 execute_console(self, string='', wildcards=[], quantifier=None): """Execute a command for the console""" command_name = string.split()[0] cmd_class = self.commands.get_command(command_name, abbrev=False) if cmd_class is None: self.notify("Command not found: `%s'" % command_name, bad=True) return cmd = cmd_class(string) if cmd.resolve_macros and _MacroTemplate.delimiter in string: macros = dict(('any%d'%i, key_to_string(char)) \ for i, char in enumerate(wildcards)) if 'any0' in macros: macros['any'] = macros['any0'] try: string = self.substitute_macros( string, additional=macros, escape=cmd.escape_macros_for_shell) except ValueError as e: if ranger.arg.debug: raise else: return self.notify(e) try: cmd_class(string, quantifier=quantifier).execute() except Exception as e: if ranger.arg.debug: raise else: self.notify(e)
def _draw_hints(self): self.columns[-1].clear_image(force=True) self.need_clear = True hints = [] for key, value in self.fm.ui.keybuffer.pointer.items(): key = key_to_string(key) if isinstance(value, dict): text = '...' else: text = value if text.startswith('hint') or text.startswith('chain hint'): continue hints.append((key, 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) try: self.win.chgat(ystart - 1, 0, curses.A_UNDERLINE) except curses.error: pass 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 populate_hints(keymap, prefix=""): for key, value in keymap.items(): key = prefix + key_to_string(key) if isinstance(value, dict): populate_hints(value, key) else: text = value if text.startswith('hint') or text.startswith('chain hint'): continue hints.append((key, text))
def populate_hints(keymap, prefix=""): for key, value in keymap.items(): key = prefix + key_to_string(key) if isinstance(value, dict): populate_hints(value, key) else: text = value if text.startswith('hint') or text.startswith( 'chain hint'): continue hints.append((key, text))