ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
Code:
static void display_image (char *buf)
{
int old = log_set_save_context (0);
logputs (LOG_VERBOSE, "\r");
logputs (LOG_VERBOSE, buf);
log_set_save_context (old);
}
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.
Ntubski is right. Upon rereading the code snippet they are just using a carriage return. If one line isn't enough, I'd go with ncurses rather than try to use any raw terminfo, etc. It's just simpler.
So I would probably need to use c style outputs to interface that way.
I will probably put this project on a GUI, probably end up being easier and more robust to use without having to deal with abstract libraries or methods.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.