This is a question for python language, and the terminal/console applies to Unix-like systems. It would be great if the solution is platform independent but that is not required.
The scenario is when the program keeps printing lines to terminal. However, among the many lines to print, some of them are special, like progress bar or status indicator: they have to be placed only at the bottom of the console, while all other lines can still be printed where they normally are, one after another and the screen scrolls as normal too.
An example code solution would be much better than a theoretic one. For this purpose here is an example:
def print_status(msg):
# implement me
print msg
def print_many_lines():
print 'line one\n'
print 'line two\n'
print_status('i am here')
print 'line three\n'
print 'line four\n'
print 'line five\n'
print_status('i am changed')
print 'line six\n'
Could you help me implement the print_status function so that the msg passed to it will always be printed at the bottom of terminal?
Please note that this is very different from another similar question that, when multiple lines are printed consecutively to the terminal, how can we make sure they are printed at the same line. Using \r can be useful in that scenario but it cannot solve this problem, because (1) these special lines may more likely not be printed consecutively and (2) there will be other lines printed after these special lines but these special lines should be kept at the bottom of terminal, still.
Thanks!