def perror(self, msg: str = '', *, end: str = '\n', apply_style: bool = True) -> None: if apply_style: final_msg = ansi.style_error(msg) else: final_msg = "{}".format(msg) ansi.style_aware_write(sys.stderr, final_msg + end)
def perror(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) -> None: """Override perror() method from `cmd2.Cmd` Use colorama native approach for styling the text instead of `cmd2.ansi` methods :param msg: message to print (anything convertible to a str with '{}'.format() is OK) :param end: string appended after the end of the message, default a newline :param apply_style: If True, then ansi.style_error will be applied to the message text. Set to False in cases where the message text already has the desired style. Defaults to True. """ if apply_style: final_msg = "{}{}{}{}".format(Fore.RED, Back.YELLOW, msg, Style.RESET_ALL) else: final_msg = "{}".format(msg) ansi.style_aware_write(sys.stderr, final_msg + end)
def print_pivot_table(self): bold = functools.partial(ansi.style, bold=True) columns: List[Column] = list() columns.append(Column(bold("ID"), width=5)) columns.append(Column(bold("Alive"), width=6)) columns.append(Column(bold("Socks Port"), width=12)) columns.append(Column(bold("PID"), width=10)) columns.append(Column(bold("User"), width=25)) columns.append(Column(bold("Computer"), width=25)) columns.append(Column(bold("Last"), width=12)) data_list: List[List[Any]] = list() for pivot in ProxyPivots.instances.values(): data_list.append(pivot.get_list()) bt = BorderedTable(columns, column_borders=False) table = bt.generate_table(data_list) ansi.style_aware_write(sys.stdout, table + '\n\n')
def print_generic_table(self, data): columns: List[Column] = list() data_list: List[List[Any]] = list() max_len0 = 0 max_len1 = 0 for row in data: col_len = len(row[0]) if col_len > max_len0: max_len0 = col_len col_len = len(row[1]) if col_len > max_len1: max_len1 = col_len data_list.append(row) columns.append(Column("", width=max_len0)) columns.append(Column("", width=max_len1)) bt = BorderedTable(columns) table = bt.generate_table(data_list, include_header=False) ansi.style_aware_write(sys.stdout, table + '\n\n')
def ansi_print(text): """Wraps style_aware_write so style can be stripped if needed""" ansi.style_aware_write(sys.stdout, text + '\n\n')
def poutput(self, msg: str = "", *, end: str = "\n") -> None: ansi.style_aware_write(sys.stdout, "{}{}".format(msg, end))
def perror(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) -> None: if apply_style: final_msg = ansi.style_error(msg) else: final_msg = str(msg) ansi.style_aware_write(self.stdout, final_msg + end)