Skip to content

Commit

Permalink
Avoid word wrap messing up on-screen disappearing text
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jun 18, 2024
1 parent ec7d60c commit fc9d135
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions jarvis/modules/utils/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,15 @@ def write_screen(text: Any) -> None:
"""
if shared.called_by_offline:
return
flush_screen()
text = str(text).strip()
if models.settings.interactive:
term_size = os.get_terminal_size().columns
sys.stdout.write(f"\r{' ' * term_size}")
if len(text) > term_size:
# Get 90% of the text size and ONLY print that on screen
size = round(term_size * (90 / 100))
sys.stdout.write(f"\r{text[:size].strip()}...")
return
sys.stdout.write(f"\r{text}")


Expand All @@ -471,9 +479,7 @@ def flush_screen() -> None:
Writes new set of empty strings for the size of the terminal if ran using one.
"""
if models.settings.interactive:
sys.stdout.write(
f"\r{' '.join(['' for _ in range(os.get_terminal_size().columns)])}"
)
sys.stdout.write(f"\r{' ' * os.get_terminal_size().columns}")
else:
sys.stdout.write("\r")

Expand Down

0 comments on commit fc9d135

Please sign in to comment.