I'm making a chat application with Python 2. No GUI, all CLI. I'm trying to think of a way to always make sure the raw_input prompt that's waiting for a command, including everything the user has typed so far, is always the last thing shown. Doesn't need to be at the bottom of the user's view, necessarily. Just needs to be below everything else that's happened so far.
Thing is, if someone else sends a message to the user, it'll look confusing and sloppy when the message pops up in the prompt and then the cursor gets moved down with no prompt, etc.
For example:
--- Started chat ---
Input: Hello. Good to meeReceived: Hi there!
t you. ('Enter')
Input:
In this example, the user receives a message in the middle of typing "meet". The user can still send the message after typing "you", and the other user will still receive "Hello. Good to meet you." but this still obviously looks bad. This could also happen when the user is trying to type a command to the application in the input, not always a message to someone else, or when nothing has been typed at all. Ideally, the output from some other thread would print, and the input line so far would look like it was just pushed down.
I need this to work on Windows as well as other systems, so I don't think I can use curses, or libraries made with curses like urwid or npyscreen suggested here. I had the idea that the thread listening for messages could just somehow copy what's on the prompt line so far, then remove the text on the line, display a message, and then print the copied input line on a new line so the cursor would be right back where it was. Is that possible? Is there a way to accomplish this in some other windows/unix/linux friendly way?