I\'ve run command line programs that output a line, and then update that line a moment later. But with ruby I can only seem to output a line and then another line.
Use \r
to move the cursor to the beginning of the line. And you should not be using puts
as it adds \n
, use print
instead. Like this:
print "11MB 294K/s"
print "\r"
print "12MB 307K/s"
One thing to keep in mind though: \r
doesn't delete anything, it just moves the cursor back, so you would need to pad the output with spaces to overwrite the previous output (in case it was longer).
By default when \n
is printed to the standard output the buffer is flushed. Now you might need to use STDOUT.flush
after print
to make sure the text get printed right away.