feat: add compact file listing using rich Columns when pretty=True

This commit is contained in:
Paul Gauthier (aider) 2024-10-31 14:43:25 -07:00
parent 4c39e92773
commit 42abdb0a41

View file

@ -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):