self._lines_t = self._lines_t[fragments_cutoff + 1:]
break
- @staticmethod
- def _args_verbose(args: tuple[str, ...]) -> str:
- return ' '.join(f'[{arg}]' for arg in args)
-
@staticmethod
def _args_for_cmd(cmd_name: str, remains: str) -> tuple[str, ...]:
n_args = _SIGNATURE_FOR_CMD[cmd_name][0]
def _current_line(self) -> 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
+ def _log_columns(self, *items) -> None:
+ col_titles = ('line number(s)', 'command', 'arguments')
+
+ def args_verbose(args: tuple[str, ...]) -> str:
+ return ' '.join(f'[{arg}]' for arg in args)
+
+ def print_padded(to_pad: tuple[str, ...], unpadded_end: str) -> None:
+ to_log = []
+ for idx, colname in enumerate(col_titles[:len(to_pad)]):
+ text = to_pad[idx]
+ to_log += [text + ' ' * (self._colwidths[colname] - len(text))]
+ to_log += [unpadded_end]
+ if self._verbose:
+ print(*to_log)
+ else:
+ self._print_on_fail += [' '.join(to_log)]
if not hasattr(self, '_colwidths'):
self._colwidths: dict[str, int] = {}
cmd_name, args = self._cmdname_and_args_from(line)
for idx, value in enumerate((idx_str,
cmd_name,
- self._args_verbose(args[:-1]))):
+ 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(col_titles[:-1][:len(items) - 1]):
- msg = items[idx]
- to_print += [msg + ' ' * (self._colwidths[colname] - len(msg))]
- to_print += [items[-1]]
- if self._verbose:
- print(*to_print)
- else:
- self._print_on_fail += [' '.join(to_print)]
+ to_cmp = [len(value), self._colwidths.get(title, 0)]
+ if idx < len(col_titles) - 1:
+ to_cmp += [len(title)]
+ self._colwidths[title] = max(to_cmp)
+ print_padded(to_pad=col_titles[:-1],
+ unpadded_end=col_titles[-1])
+
+ print_padded(to_pad=items[:2] + (args_verbose(items[2:-1]),),
+ unpadded_end=items[-1])
def ensure_has_started(self) -> None:
'Check if still at beginning, and if so, play till at next log line.'
def _play_till_test(self) -> None:
while True:
if self._idx >= len(self._lines_t):
- self._lines_t += [('', '> /quit'), ('', 'log 0 <..')]
+ self._lines_t += [('', '> /quit'),
+ ('', 'log 0 <..')]
idx_info, line = self._current_line
cmd_name, args = self._cmdname_and_args_from(line)
- self._log_verbose_columns((idx_info, cmd_name,
- self._args_verbose(args[:-1]),
- self._args_verbose(args[-1:])))
+ self._log_columns(idx_info, cmd_name, *args)
if cmd_name == _MARK_PROMPT:
assert self.put_keypress is not None
for c in args[0]: