mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
feat: Clip spinner output to console width
This commit is contained in:
parent
781ed90653
commit
df967e4b41
1 changed files with 14 additions and 3 deletions
|
@ -353,8 +353,19 @@ class Spinner:
|
||||||
self.last_update = now
|
self.last_update = now
|
||||||
frame_str = self._next_frame()
|
frame_str = self._next_frame()
|
||||||
|
|
||||||
|
# Determine the maximum width for the spinner line
|
||||||
|
# Subtract 2 as requested, to leave a margin or prevent cursor wrapping issues
|
||||||
|
max_spinner_width = self.console.width - 2
|
||||||
|
if max_spinner_width < 0: # Handle extremely narrow terminals
|
||||||
|
max_spinner_width = 0
|
||||||
|
|
||||||
current_text_payload = f" {self.text}"
|
current_text_payload = f" {self.text}"
|
||||||
line_to_display = f"{frame_str}{current_text_payload}"
|
line_to_display = f"{frame_str}{current_text_payload}"
|
||||||
|
|
||||||
|
# Truncate the line if it's too long for the console width
|
||||||
|
if len(line_to_display) > max_spinner_width:
|
||||||
|
line_to_display = line_to_display[:max_spinner_width]
|
||||||
|
|
||||||
len_line_to_display = len(line_to_display)
|
len_line_to_display = len(line_to_display)
|
||||||
|
|
||||||
# Calculate padding to clear any remnants from a longer previous line
|
# Calculate padding to clear any remnants from a longer previous line
|
||||||
|
@ -362,8 +373,6 @@ class Spinner:
|
||||||
|
|
||||||
# Write the spinner frame, text, and any necessary clearing spaces
|
# Write the spinner frame, text, and any necessary clearing spaces
|
||||||
sys.stdout.write(f"\r{line_to_display}{padding_to_clear}")
|
sys.stdout.write(f"\r{line_to_display}{padding_to_clear}")
|
||||||
|
|
||||||
# Store the length of the actual content part for the next step's clearing calculation
|
|
||||||
self.last_display_len = len_line_to_display
|
self.last_display_len = len_line_to_display
|
||||||
|
|
||||||
# Calculate number of backspaces to position cursor at the scanner character
|
# Calculate number of backspaces to position cursor at the scanner character
|
||||||
|
@ -372,8 +381,10 @@ class Spinner:
|
||||||
# Total characters written to the line (frame + text + padding)
|
# Total characters written to the line (frame + text + padding)
|
||||||
total_chars_written_on_line = len_line_to_display + len(padding_to_clear)
|
total_chars_written_on_line = len_line_to_display + len(padding_to_clear)
|
||||||
|
|
||||||
|
# num_backspaces will be non-positive if scan_char_abs_pos is beyond total_chars_written_on_line
|
||||||
|
# (e.g., if the scan char itself was truncated).
|
||||||
|
# In such cases, (effectively) 0 backspaces are written, and the cursor stays at the end of the line.
|
||||||
num_backspaces = total_chars_written_on_line - scan_char_abs_pos
|
num_backspaces = total_chars_written_on_line - scan_char_abs_pos
|
||||||
|
|
||||||
sys.stdout.write("\b" * num_backspaces)
|
sys.stdout.write("\b" * num_backspaces)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue