I try to replace the text printed on a given line by another. For that, I have been using ANSI escape codes. My problem is when the line to be replaced is not visible on the screen anymore (but still visible by scrolling up the window) I don't seem to be able to modify it anymore. Here is a simple standalone example of my problem :
import os
nb_lines_term = int(os.popen('stty size', 'r').read().split()[0])
tot_lines = nb_lines_term + 5
for i in range(tot_lines):
print 'line', tot_lines - i
line_to_replace = nb_lines_term + 2
new_str = "\033[F" * line_to_replace # go u
new_str += 'replacing line ' + str(line_to_replace)
new_str += "\033[E" * (line_to_replace - 1) # go back down
print new_str
Is there a way to access the line still? by ANSI escape codes or any other method?