如何tcl打印控制字符

时间:2014-09-28 00:42:28

标签: tcl

如何在同一行重复打印? 即一个百分点的反击直到一些过程完成? 我希望在xterm行上,百分比数字在不滚动的情况下倒数。

如果我这样做

puts -nonewline "10%"
puts -nonewline "9%"
puts -nonewline "8%"
puts -nonewline "7%"

我明白了:

10%9%8%7%....

看起来不对。

诀窍是什么?

谢谢, 格特

1 个答案:

答案 0 :(得分:2)

您需要回车才能将光标发送到该行的开头:

for {set i 10} {$i>0} {incr i -1} {
    puts -nonewline [format "\r%2d%%" $i]
    flush stdout
    after 200
}; puts ""
相关问题