Skip to content

Instantly share code, notes, and snippets.

@TheBigRoomXXL
Last active July 22, 2024 08:19
Show Gist options
  • Save TheBigRoomXXL/2400296992573e9b47e7d1fbfd9a8ed5 to your computer and use it in GitHub Desktop.
Save TheBigRoomXXL/2400296992573e9b47e7d1fbfd9a8ed5 to your computer and use it in GitHub Desktop.
Update multiple lines of terminal output
"""Stolen from:
https://stackoverflow.com/questions/66615552/display-multi-line-python-console-ascii-animation
"""
import time
nlines = 5
# scroll up to make room for output
print(f"\033[{nlines}S", end="")
# move cursor back up
print(f"\033[{nlines}A", end="")
# save current cursor position
print("\033[s", end="")
for t in range(10):
# restore saved cursor position
print("\033[u", end="")
for i in range(nlines):
print(f"Line one @ {t}-{i}")
t += 1
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment