Daniel Daniel - 1 year ago 94
Bash Question

cursor blinking removal in terminal, how to?

I use the following lines to output my simulation's progress info in my c++ program,

double N=0;
double percent=0;
double total = 1000000;
for (int i; i<total; ++i)
percent = 100*i/total;

It works fine!

But the problem is I see the terminal cursor keeps blinking cyclically through the numbers, this is very annoying, anyone knows how to get rid of this?

I've seen some programs like wget or ubuntu apt, they use progress bar or percentages too, but they seems no blinking cursor issue, I am wondering how did they do that?


kol kol
Answer Source

Just a guess: try to use a proper number of '\b' (backspace) characters instead of '\r'.

== EDIT ==

I'm not a Linux shell wizard, but this may work:

system("setterm -cursor off");
// ...display percentages...
system("setterm -cursor on");

Don't forget to #include <cstdlib> or <iostream>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download