From 42abdb0a4174fe86d7b5ec071ce40afd706a367f Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 31 Oct 2024 14:43:25 -0700 Subject: [PATCH] feat: add compact file listing using rich Columns when pretty=True --- aider/io.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/aider/io.py b/aider/io.py index ae2967719..0261fcd11 100644 --- a/aider/io.py +++ b/aider/io.py @@ -700,17 +700,37 @@ class InputOutput: self.chat_history_file = None # Disable further attempts to write def format_files_for_input(self, rel_fnames, rel_read_only_fnames): - read_only_files = [] - for full_path in sorted(rel_read_only_fnames or []): - read_only_files.append(f"{full_path} (read only)") + if not self.pretty: + read_only_files = [] + for full_path in sorted(rel_read_only_fnames or []): + read_only_files.append(f"{full_path} (read only)") - editable_files = [] - for full_path in sorted(rel_fnames): - if full_path in rel_read_only_fnames: - continue - editable_files.append(f"{full_path}") + editable_files = [] + for full_path in sorted(rel_fnames): + if full_path in rel_read_only_fnames: + continue + editable_files.append(f"{full_path}") - return "\n".join(read_only_files + editable_files) + "\n" + return "\n".join(read_only_files + editable_files) + "\n" + + # Use rich Columns for pretty output + from rich.columns import Columns + from io import StringIO + + output = StringIO() + console = Console(file=output, force_terminal=False) + + read_only_files = [f"{f} (read only)" for f in sorted(rel_read_only_fnames or [])] + editable_files = [f for f in sorted(rel_fnames) if f not in rel_read_only_fnames] + + if read_only_files: + console.print(Columns(read_only_files)) + if editable_files: + if read_only_files: + console.print() + console.print(Columns(editable_files)) + + return output.getvalue() def get_rel_fname(fname, root):