From: Tim Pease Date: 2006-11-08T01:20:09+09:00 Subject: Re: How to make a cycling counter from commandline? On 11/7/06, Tim Pease wrote: > On 11/7/06, darenbell@gmail.com wrote: > > Hi, I'm looking for a way to implement this idea: > > > > > > ------------------------------------- > > count=1 > > total=15 > > > > until count>total > > print "Record #{count} of #{total} processed." > > count+=1 > > end > > ------------------------------------- > > > > > > $ cat tmp.rb > > STDOUT.sync = true > > total = ARGV[0] || 15 total = ARGV[0] || 15 total = Integer(total) # need to turn any passed in arguments into an integer > count = 1 > > until count>total > print "\rRecord #{count} of #{total} processed" > count += 1 > sleep 0.25 > end > > print "\n" > > > That should do you what you want. The secret is the carriage return > "\r" at the beginning of the print string. That will bring the cursor > back to the beginning of the line and then overwrite anything > currently on that line. > > Blessings, > TwP >