From 0c1c2b9351352f9c2a8a226dd62044802b806c56 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 4 Mar 2026 15:26:25 +0000 Subject: [PATCH] lib.util.run_cmd(): Reduce interactive logging run_cmd() with cmd_input == mode:interactive and verbose == true logs output too often. First, __log() is called, then pty.spawn() writes everything it reads from the PTY master to the terminal. The fix it to not call __log() from _read() for the PTY reader. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/util.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/python/jw/pkg/lib/util.py b/src/python/jw/pkg/lib/util.py index f6fd3352..119ece1b 100644 --- a/src/python/jw/pkg/lib/util.py +++ b/src/python/jw/pkg/lib/util.py @@ -81,16 +81,22 @@ async def run_cmd( if not ret: return ret collector.append(ret) - if verbose: - __log(NOTICE, ret.decode(enc_for_verbose, errors="replace").rstrip("\n")) return ret return _read + interactive = ( + cmd_input == "mode:interactive" + or (cmd_input == "mode:auto" and sys.stdin.isatty()) + ) + if verbose: delim_len = 120 delim = title if title is not None else f'---- Running {pretty_cmd(args, wd)} -' - delim += '-' * max(0, delim_len - len(delim)) - log(NOTICE, ',' + delim + ' >') + if interactive: + log(NOTICE, delim) + else: + delim += '-' * max(0, delim_len - len(delim)) + log(NOTICE, ',' + delim + ' >') cwd: str|None = None if wd is not None: @@ -100,10 +106,8 @@ async def run_cmd( try: # -- interactive mode - if cmd_input == "mode:auto" and sys.stdin.isatty(): - cmd_input = "mode:interactive" - if cmd_input == "mode:interactive": + if interactive: import pty @@ -219,7 +223,7 @@ async def run_cmd( finally: if cwd is not None: os.chdir(cwd) - if verbose: + if verbose and not interactive: log(NOTICE, '`' + delim + ' <') async def run_curl(args: list[str], parse_json: bool=True, wd=None, throw=None, verbose=False, cmd_input=None) -> dict|str: # export