终端中的光标闪烁删除,如何? [英] cursor blinking removal in terminal, how to?

查看:264
本文介绍了终端中的光标闪烁删除,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下行在我的c ++程序中输出我的模拟进度信息:

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;
    printf("\r[%6.4f%%]",percent);
}

运作正常!

但是问题是我看到终端光标通过数字循环闪烁,这是非常讨厌的,任何人都知道如何摆脱这个?

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?

我看到一些程序像wget或ubuntu apt,他们使用进度条或百分比,但他们似乎没有闪烁的光标问题,我想知道他们是如何做到这一点?

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?

谢谢!

推荐答案

只是一个猜测:尝试使用适当数量的'\b' \r'。

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

== EDIT ==

== EDIT ==

我不是Linux shell向导, / p>

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

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

不要忘记 #include< cstdlib> < iostream>

这篇关于终端中的光标闪烁删除,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆