Reputation: 64
I find it hard to explain but I will try my best.
Some times in Linux- in the Terminal- things get printed but you can still write over them. eg when using wget you get a progress bar like this:
[===================> ]
Now if you type something while it is doing this it will 'overwrite' it. My question is how to recreate this in c++.
Will you use something like
cout <<
or something else?
I hope you understand what I am getting at...
btw I am using the most recent version of Arch with xfce4
Upvotes: 1
Views: 149
Reputation: 1410
Controlling the terminal involved sending various escape sequences to it, in order to move the cursor around and such.
http://www.ibiblio.org/pub/historic-linux/ftp-archives/tsx-11.mit.edu/Oct-07-1996/info/vt102.codes
You could also use ncurses to do this.
Upvotes: 1
Reputation: 249133
You can print the special character \b
to go back one space. Then you can print a space to blank it out, or another character to overwrite what was there. You can also use \r
to return to the beginning of the current output line and write again from there.
Upvotes: 2
Reputation: 110658
Printing a carriage return character \r
is typically interpreted in Linux as returning you to the beginning of the line. Try this, for example:
std::cout << "Hello\rJ";
The output will be:
Jello
This does depend on your terminal, however, so you should look up the meaning of particular control characters for your terminal.
For a more cross-platform solution and the ability to do more complex text-based user interfaces, take a look at ncurses.
Upvotes: 4