From 31ce4903217134cbd6fc56cd5b8d747c4f821ec0 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 30 Sep 2024 18:29:17 -0700 Subject: [PATCH] fix help command output docstrings and more CLI log coloring --- archivebox/config/defaults.py | 4 +++- archivebox/logging_util.py | 2 +- archivebox/main.py | 20 +++++++++++--------- archivebox/monkey_patches.py | 8 ++++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/archivebox/config/defaults.py b/archivebox/config/defaults.py index f495523a..d1f0ac23 100644 --- a/archivebox/config/defaults.py +++ b/archivebox/config/defaults.py @@ -45,7 +45,9 @@ class ShellConfig(BaseConfigSet): @computed_field @property def TERM_WIDTH(self) -> int: - return shutil.get_terminal_size((100, 10)).columns + if not self.IS_TTY: + return 200 + return shutil.get_terminal_size((140, 10)).columns @computed_field @property diff --git a/archivebox/logging_util.py b/archivebox/logging_util.py index 32542fdf..90576d9e 100644 --- a/archivebox/logging_util.py +++ b/archivebox/logging_util.py @@ -228,7 +228,7 @@ def progress_bar(seconds: int, prefix: str='', ANSI: Dict[str, str]=ANSI) -> Non def log_cli_command(subcommand: str, subcommand_args: List[str], stdin: Optional[str | IO], pwd: str): args = ' '.join(subcommand_args) - version_msg = '[dark_magenta]\\[i] [{now}] ArchiveBox v{VERSION}: [/dark_magenta][green4]archivebox [green3]{subcommand}[green2] {args}[/green2]'.format( + version_msg = '[dark_magenta]\\[{now}][/dark_magenta] [dark_red]ArchiveBox[/dark_red] [dark_goldenrod]v{VERSION}[/dark_goldenrod]: [green4]archivebox [green3]{subcommand}[green2] {args}[/green2]'.format( now=datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S'), VERSION=VERSION, subcommand=subcommand, diff --git a/archivebox/main.py b/archivebox/main.py index d015d55b..46c16478 100755 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -96,20 +96,20 @@ def help(out_dir: Path=DATA_DIR) -> None: all_subcommands = CLI_SUBCOMMANDS COMMANDS_HELP_TEXT = '\n '.join( - f'{cmd.ljust(20)} {summary}' - for cmd, summary in all_subcommands.items() + f'{cmd.ljust(20)} {func.__doc__}' + for cmd, func in all_subcommands.items() if cmd in meta_cmds ) + '\n\n ' + '\n '.join( - f'{cmd.ljust(20)} {summary}' - for cmd, summary in all_subcommands.items() + f'{cmd.ljust(20)} {func.__doc__}' + for cmd, func in all_subcommands.items() if cmd in main_cmds ) + '\n\n ' + '\n '.join( - f'{cmd.ljust(20)} {summary}' - for cmd, summary in all_subcommands.items() + f'{cmd.ljust(20)} {func.__doc__}' + for cmd, func in all_subcommands.items() if cmd in archive_cmds ) + '\n\n ' + '\n '.join( - f'{cmd.ljust(20)} {summary}' - for cmd, summary in all_subcommands.items() + f'{cmd.ljust(20)} {func.__doc__}' + for cmd, func in all_subcommands.items() if cmd not in display_first ) @@ -127,8 +127,10 @@ def help(out_dir: Path=DATA_DIR) -> None: {} {lightred}Example Use:{reset} - mkdir my-archive; cd my-archive/ + mkdir -p ~/archivebox/data; cd ~/archivebox/data archivebox init + archivebox setup + archivebox version archivebox status archivebox add https://example.com/some/page diff --git a/archivebox/monkey_patches.py b/archivebox/monkey_patches.py index 2fb77d5b..ad6fdd3f 100644 --- a/archivebox/monkey_patches.py +++ b/archivebox/monkey_patches.py @@ -1,8 +1,9 @@ __package__ = 'archivebox' +import sys +import shutil import django import pydantic -import shutil import django_stubs_ext @@ -21,9 +22,12 @@ timezone.utc = datetime.timezone.utc # Install rich for pretty tracebacks in console logs # https://rich.readthedocs.io/en/stable/traceback.html#traceback-handler + from rich.traceback import install -install(show_locals=True, word_wrap=False, locals_max_length=10, locals_hide_dunder=True, suppress=[django, pydantic], extra_lines=2, width=shutil.get_terminal_size((100, 10)).columns - 1) +TERM_WIDTH = (shutil.get_terminal_size((200, 10)).columns - 1) if sys.stdout.isatty() else 200 +# os.environ.setdefault('COLUMNS', str(TERM_WIDTH)) +install(show_locals=True, word_wrap=False, locals_max_length=10, locals_hide_dunder=True, suppress=[django, pydantic], extra_lines=2, width=TERM_WIDTH) from daphne import access