Normally if the content can be print only in one line in terminal, flush=True can do it perfectly, but if the length is too long that it takes maybe 2 lines, flush can not clear the first line but the second line.
is it possible that i can clear these two lines and print the new stuff instead?
code:
content = [i for i in range(11)]
print(content, flush=True, end="\r")
content.append(11)
print(content, flush=True, end="\r")
output:
# before second print
(first line) [0, 1, 2, 3, 4,
(second line) 5, 6, 7, 8, 9,
(thrid line) 10]
# after second print
(first line) [0, 1, 2, 3, 4,
(second line) 5, 6, 7, 8, 9,
(second print replaced) [0, 1, 2, 3, 4,
(second print replaced) 5, 6, 7, 8, 9,
(second print replaced) 10, 11]
# what i want
# clear all the three lines in the first print and replace them
(second print replaced) [0, 1, 2, 3, 4,
(second print replaced) 5, 6, 7, 8, 9,
(second print replaced) 10, 11]
Interesting puzzle.
Here is how I tackled it and you can develop it further to what you want.
I took 6 long text lines from here
I made it chuck the long line text and used
.instead of space as a blank so its clear whats happening. I have a clip set to 4 just so you can see the end which is overwritten each time with..Alternatively there are curses (which I detest working with) but they would cleanly do what you want. There was another newer curses lib but sadly i cant find that for you.
EDIT: Found it. Try that out https://textual.textualize.io/