To simplify, let's say I'm trying to write a command line two-way chat in Python. I would like the user to input his message with
userB>Stop interuserA wrote:Hey check this out!
userA says: Ok I won't interrupt you
There are two ways of doing this.
One is to use
ncurses. There are python bindings for this. With
ncurses, the terminal screen is under your complete control, and you can print characters at any point.
ncurses, you can't write above the current line. What you can do, however, is print a
\r character and go back to the beginning of the line.
If you save the user's input (say he wrote
foo), and you want to print the line
bar above that, you can output:
This will overwrite the current line, and introduce a newline, moving the user's input down. The effect is similar, but it won't be as tamper-proof as