assert_screen_line: Optional[Callable] = None
redraw_affected: Optional[Callable] = None
_lines_t: list[tuple[str, str]]
+ _colwidths: dict[str, int]
def __init__(self, path: Path, get_client: Callable, verbose: bool
) -> None:
and not line.startswith(_MARK_COMMENT)]
expand_inserts()
expand_parsed(_MARK_LOGSRVRMSG, split_server_put_and_log)
- title_idx = 'line number(s)'
- title_cmdname = 'command'
- self._colwidths: dict[str, int] = {}
- for idx_str, line in self._lines_t:
- self._colwidths['idx'] = max(
- len(title_idx),
- len(idx_str),
- self._colwidths.get('idx', 0))
- cmd_name, args = self._cmdname_and_args_from(line)
- self._colwidths['cmdname'] = max(
- len(title_cmdname),
- len(cmd_name),
- self._colwidths.get('cmdname', 0))
- self._colwidths['midargs'] = max(
- len(self._args_verbose(args[:-1])),
- self._colwidths.get('midargs', 0))
- self._log_verbose_columns((title_idx, title_cmdname, 'arguments'))
@staticmethod
def _args_verbose(args: tuple[str, ...]) -> str:
return self._lines_t[self._idx]
def _log_verbose_columns(self, items: tuple[str, ...]) -> None:
+ col_titles = (
+ 'line number(s)', # = idx_str
+ 'command', # = cmd_name
+ '', # = last two both "arguments", but empty key to
+ 'arguments') # … harvest width on non-last (middle) args
+
+ if not hasattr(self, '_colwidths'):
+ self._colwidths: dict[str, int] = {}
+ for idx_str, line in self._lines_t:
+ cmd_name, args = self._cmdname_and_args_from(line)
+ for idx, value in enumerate((idx_str,
+ cmd_name,
+ self._args_verbose(args[:-1]))):
+ title = col_titles[idx]
+ self._colwidths[title] = max(len(title),
+ len(value),
+ self._colwidths.get(title, 0))
+ self._log_verbose_columns(tuple(t for t in col_titles if t))
+
to_print = []
- for idx, colname in enumerate(('idx', 'cmdname', 'midargs'
- )[:len(items) - 1]):
+ for idx, colname in enumerate(col_titles[:-1][:len(items) - 1]):
msg = items[idx]
to_print += [msg + ' ' * (self._colwidths[colname] - len(msg))]
to_print += [items[-1]]