From 2affb111ad0f460dba9bb519b873ac2195f299cf Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sun, 14 Jul 2024 18:46:54 +0100 Subject: [PATCH] Read character by character and update the spinner every newline or every 100 characters received in the `run_install` function. --- aider/utils.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index 2aef5eff2..929d8b5fa 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -207,24 +207,36 @@ def run_install(cmd): universal_newlines=True, ) spinner = itertools.cycle(["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]) + char_count = 0 + current_line = "" - for line in process.stdout: - output.append(line) - print(f" Installing... {next(spinner)}", end="\r", flush=True) + while True: + char = process.stdout.read(1) + if not char: + break + + current_line += char + char_count += 1 + output.append(char) + + if char == '\n' or char_count >= 100: + print(f" Installing... {next(spinner)}", end="\r", flush=True) + char_count = 0 + current_line = "" return_code = process.wait() if return_code == 0: print("\rInstallation complete.") print() - return True, output + return True, ''.join(output) except subprocess.CalledProcessError as e: print(f"\nError running pip install: {e}") print("\nInstallation failed.\n") - return False, output + return False, ''.join(output) def check_pip_install_extra(io, module, prompt, pip_install_cmd):