Ruby comes pre-packaged with a curses library that (supposedly) works
with both Linux and Windows. It is completely undocumented (that I
can find), but the C Curses library may help. Have a look at:
then when it is done with that directory replace that line with the
next, not create another below it.
I have been unable to locate information about this, though I don’t
really know what to call it.
Thank you.
I think this will work in Windows but I don’t have it to test. It works
in OS X and Linux terminal windows.
Instead of terminating the output line with a \n (or allowing it to
default to a \n), use \r instead. “\r” is a carriage return, so the
cursor will return to the start of the same line and overprint it.
For example,
10.times { |n| printf(“Hello %d\r”, n);sleep 1 }
Will print
Hello 0
Hello 1
Hello 2
etc., except each new “Hello” line overprints the previous one so you
only see 1 line.
Similar to Tim H.'s suggestion: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/336734
… to show progress in a “console” box I just repeatedly use (every
second):
print 13.chr + “text to show progress”
This - and presumably Tim H.'s code - runs under Linux and Windows.
Actually I think I prefer Tim H.'s formulation. (It’s OK for me to
say
that because the post just above was from me!)
.
If you want “multi line” changes this post uses curses and -
apparently -
works on both Linux and Windows. http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/336742
… This is based on the “hello.rb” example in the following place on my
Win32 Ruby installation:
C:/ruby/src/ruby-1.8.6-p111/ext/curses