def guildfile_console_help(guildfile, model_desc=None, strip_ansi_format=False): out = ConsoleFormatter() out.start_section("OVERVIEW") _write_console_help_overview(guildfile, model_desc, out) _gen_write_help(guildfile, out, fmt_section_title=str.upper) s = "".join(out.buffer) if strip_ansi_format: s = ansi_util.strip_ansi_format(s) return s
def _table_item_out( formatted_item, data_item, cols, col_info, detail, detail_cb, indent, max_col_width, err, file, style_kw, ): indent_padding = " " * indent click.echo(indent_padding, file=file, nl=False, err=err) line_pos = indent for i, col in enumerate(cols): val = formatted_item[col] last_col = i == len(cols) - 1 val = _pad_col_val(val, col, col_info) if not last_col else val val_display_len = len(ansi_util.strip_ansi_format(val)) line_pos = line_pos + val_display_len if max_col_width is not None: display_val = val[:-(line_pos - max_col_width)] else: display_val = val if max_col_width is not None and line_pos > max_col_width: click.echo( style(display_val, **style_kw), file=file, nl=False, err=err, ) break else: click.echo(style(val, **style_kw), file=file, nl=False, err=err) click.echo(file=file, err=err) terminal_width = click.get_terminal_size()[0] if detail_cb: detail_cb(data_item) else: for key in detail or []: click.echo(indent_padding, file=file, nl=False, err=err) formatted = _format_detail_val(formatted_item[key], indent, terminal_width) click.echo( style(" %s:%s" % (key, formatted), **style_kw), file=file, err=err, )
def _maybe_strip_ansi(s): if _isatty: return s return ansi_util.strip_ansi_format(s)
def _format_record(self, r): msg = self._handler().format(r) if self._strip_ansi_format: msg = ansi_util.strip_ansi_format(msg) return msg