def read_command(ctx): try: _, _, type_name = is_of_builtin_type(ctx.target) if ctx.only_info_visible: action = get_default_action(ctx.target) else: action = 'i' type_name_color = style(Fore.LIGHTRED_EX, type_name, for_readline=True) type_name_color += ' ' if type_name else '' action_color = style(Fore.CYAN, action, for_readline=True) action_color += ' ' if action else '' cmd_raw = input(type_name_color + action_color + '> ').strip() terminal.prefill_input() if not cmd_raw: # execute suggested action: cmd_raw = action # just do nothing and print next prompt: #raise goto.NextCommand try: user_inp = shlex.split(cmd_raw, posix=True) except Exception as ex: print_error(f"Invalid syntax. {exc_to_str(ex)}.") raise goto.NextCommand except EOFError: # CTRL+D raise goto.Stop(exit=False) except KeyboardInterrupt: # CTRL+C raise goto.Stop(exit=True) cmd_alias, *cmd_usr_args = user_inp return cmd_raw, cmd_alias, tuple(cmd_usr_args)
def get_lines(): if header is not None: yield header for name, feat in table.items(): line = f'{name:<{width}}: {feat}' if hlight and feat.value: line = style(Style.BRIGHT, line) yield line
def cmd_info(self): """Show basic information about the target object. See also 'Features' command. """ expr = f'{self.ctx.readable:^{shutil.get_terminal_size().columns}}' header = style(Back.LIGHTBLUE_EX + Fore.WHITE + Style.BRIGHT, expr) terminal.clear() print_target_features(self.ctx.target, MAJOR_FEATURES, hlight=True, header=header) self.ctx.only_info_visible = True
def cmd_history(self): """Display history. See also '..', '-', '/' commands. """ for entry, current in self.ctx.mgr.get_history(dialect.Readable()): if current: print(style(Style.BRIGHT, entry)) else: print(entry)
def str_func(mode, item): name, transformation = item attr = transformation.result available = transformation.available base = None if available: braces = '' if is_callable(attr): try: builtin_name = attr.__name__ except AttributeError: pass else: if builtin_name != name: braces += builtin_name braces += get_signature(attr) if is_subscribable(attr): braces += '[]' if is_iterable(attr): braces += '*' if name or braces: name_color = fr'{style(Style.BRIGHT, name)}' if name else '' sep = ':' if mode == 'dict' else '' braces_color = fr'{style(Fore.LIGHTGREEN_EX, braces)}' if braces else '' base = ' '.join(x for x in (name_color, sep, braces_color) if x) if attr is None: type_name = None value = repr(attr) elif is_callable(attr): if inspect.isclass(attr): try: type_name = type(attr).__name__ except: type_name = '?' type_name = f'<{type_name}>' type_name = style(Fore.LIGHTRED_EX, type_name) value = repr(str(attr)) else: type_name = None value = None elif is_of_builtin_type(attr)[0]: type_name = None value = repr(attr).splitlines()[0] # what if multiline elif isinstance(attr, FrameSummary): type_name = None location = style(Fore.LIGHTRED_EX, f'{attr.file_name}:{attr.line_no}') callable_name = style(Fore.LIGHTBLUE_EX, f'[{attr.callable_name}]') code_line = attr.line value = f"{location} {callable_name} {code_line}" else: try: type_name = type(attr).__name__ except: type_name = '?' type_name = f'<{type_name}>' type_name = style(Fore.LIGHTRED_EX, type_name) value = repr(str(attr)) if value is not None: value = style(Fore.LIGHTBLUE_EX, value) info = [base, type_name, value] else: if name: base = fr'{style(Style.BRIGHT, name)}' info = [base, 'N/A'] return ' '.join( (x for x in info if x) )