ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I always wondered how programs like wget and top create interfaces that can be updated without throwing out new lines of output.
I managed to dig out the function used to update the progress bar in wget:
static void display_image (char *buf)
int old = log_set_save_context (0);
logputs (LOG_VERBOSE, "\r");
logputs (LOG_VERBOSE, buf);
My question is: how can you do the equivilent using strictly c++ stdlib or a library of some sort (I want to avoid using C and C++ outputs concurrently to avoid the performance issues).
Basically what I am trying to do is write a simple command line that may have text added above well after the prompt has been written to the terminal emulator. So far I have hit a pretty bad wall and have run out of ideas.
While I'm not certain, I think they are using the terminfo library to do this, which is what ncurses is built on top of. Unfortunately, that's a pure C library and I think if you use it, you need to do so exclusively (I think). That is, if you use the terminfo/curses way of printing to the screen, you shouldn't mix in printf()'s or cout<<'s.
I think the wget function only changes stuff on the current line. If that's all you want, printing a carriage return ('\r') character will send the cursor back to the beginning of the line in most terminals. If you want to go above the current line you'll need ncurses or terminfo.
hmm, interesting bit. I may end up having to go with a ncurses type system. Does anyone know anything about terminfo, all the information I have looked up has basically described it just as a database explaining the capabilities of the terminal.
I wonder how hard it would be to derive something from cout or an existing output stream and see how hard it would be to write my own. I might beable to cache the existing text, erase it, output the new text, then place the text back. I guess I have some stuff to test.