Reputation: 1716
How do I print something repeatedly on the same line? I.e. a percent down-counter until some proc is done? I wish that on the xterm line the percent numbers are counting down without scrolling.
If I do
puts -nonewline "10%"
puts -nonewline "9%"
puts -nonewline "8%"
puts -nonewline "7%"
I get:
10%9%8%7%....
That doesn't look right.
What's the trick?
Thanks, Gert
Upvotes: 0
Views: 435
Reputation: 246807
You want a carriage return to send the cursor to the start of the line:
for {set i 10} {$i>0} {incr i -1} {
puts -nonewline [format "\r%2d%%" $i]
flush stdout
after 200
}; puts ""
Upvotes: 2