在终端或控制台中就地进度输出 [英] In-place progress output in the terminal or console

查看:67
本文介绍了在终端或控制台中就地进度输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行git clone时,它会更新进度.例如,接收到的对象的百分比发生了变化.

When you run git clone, it updates progress in place. For example, the percentage of the objects received changes in place.

user@athena:~/cloj/src$ git clone git://git.boinkor.net/slime.git
Initialized empty Git repository in /home/user/cloj/src/slime/.git/
remote: Counting objects: 15936, done.
remote: Compressing objects: 100% (5500/5500), done.
Receiving objects:  28% (4547/15936), 3.16 MiB | 165 KiB/s

这是如何完成的?它使用ncurses还是更简单的东西,例如退格字符和常规字符输出的某种组合?

How is this acccomplished? Does it use ncurses or something even simpler, like some combination of backspace characters and regular character output?

我对如何从Ruby实现这种控制台输出特别感兴趣.

I'm especially interested in how this kind of console output could be accomplished from Ruby.

编辑

我的原始问题得到了回答.但是这里有一个附录.例如,当您使用MPlayer时,它不仅更新一行以显示当前进度,而且还更新上一个行(例如,当您按下暂停时).

My original question is answered. But here's an addendum. When you use MPlayer, for example, it not only updates a line to show current progress, but also the previous line (e.g. when you press pause).

 =====  PAUSE  =====
A:  79.9 (01:19.9) of 4718.0 ( 1:18:38.0)  0.3% 

您将如何就地更新两行输出?

How would you update two lines of output in-place?

推荐答案

使用回车符. '\ r'通常应该可以工作.

Use carriage return. '\r' should usually work.

这篇关于在终端或控制台中就地进度输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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