Question

I'm curious to know how you can draw/update a certain region of the terminal/console. Is there any cross-platform libraries to do so?

The reason I want to know is because I am developing an instant message command line application, and I was curious to know how I can update the message viewer (where all the messages go) separately to where you write commands/text for other people in the chat. Obviously if I just tried to get input and write to cout then the input the user is entering and the messages would be "interfered" (by interfered I mean split in multiple lines).

I was thinking of using two stream objects: one to store the view (messages/output from the server) and one to store the input from the user, and just redraw whenever required. However, this seems inefficient and it requires me to clear the screen (in which case I don't know how to clear the screen efficiently and in a cross-platform manner).

I was also thinking of just switching to Qt/wxWidgets as it might simpler to make a GUI.

Was it helpful?

Solution

Use ncurses library to write text-based user interfaces in a terminal-independent manner.

OTHER TIPS

As suggested by @Naruto, ncurses is a good way to go. At a much more basic level, you can also just use ANSI escape codes to move the cursor around the screen too:

For example, to position the cursor at line 5, column 23, you can enter this

echo -n "\033[5;23H"

There are more examples here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top