Last active
July 22, 2024 08:19
-
-
Save TheBigRoomXXL/2400296992573e9b47e7d1fbfd9a8ed5 to your computer and use it in GitHub Desktop.
Update multiple lines of terminal output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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