Gabriele Marrone
11/2/2006 12:37:00 AM
Il giorno 02/nov/06, alle ore 01:21, Lucas Handelsman ha scritto:
> but I don't want a linebreak after the counter is displayed. I
> want it
> just to keep refreshing itself, basically. Am I missing something
> with
> puts or print or p? Any ideas?
This isn't language dependent, and there isn't a "standard" way which
will work under every environment.
Under Unix you can print the character \r to go back to the beginning
of the line, but keep in mind that stdout (unlike stderr) is line
buffered: by default, it prints its output just when a line break is
found. If you want to force it to write to your console, you have to
flush it manually.
Try something like this:
10.times do |i|
print "\r#{i} "
sleep 0.5
$stdout.flush
end
print "\n"
I don't think it would work under Windows. Does it?
Anyway, even if it won't work on a specific console, the user will be
able to understand its output anyway (especially because of the space
I left at the end of the string), so it shouldn't be a big issue.