Overprinting characters

I have a script that does things to large files > 1Gb and I want to be
able to show the percentage through the current file.

I know exactly how I will get the percentage, but I want to know how to
display it in the terminal.

What I would like is the name of the current file, then on the next
line, “currentbytes/totalbytes [xx%]” and I want it to update the
characters in place without writing hundreds of lines to the terminal.

I think I want to be able to position the cursor back to the beginning
of the current line but I have no idea how to do this in ruby.

Grateful for any ideas

Thanks

Matt

Matt H. wrote:

I think I want to be able to position the cursor back to the beginning
of the current line but I have no idea how to do this in ruby.

Grateful for any ideas

Thanks

Matt

You can use curses with Ruby to do what you want. Otherwise if you can
figure out how to get Ruby to properly handle the CR character that may
be a simpler way. I am not sure how to get Ruby to print a character
without interpreting it – i.e. print 0xa prints 10 instead of a
carriage return.

-------- Original-Nachricht --------

Datum: Wed, 20 Aug 2008 07:20:58 +0900
Von: Matt H. [email protected]
An: [email protected]
Betreff: overprinting characters

I think I want to be able to position the cursor back to the beginning
of the current line but I have no idea how to do this in ruby.

Grateful for any ideas

Thanks

Matt

Dear Matt,

try this:

"puts" without line feed - Ruby - Ruby-Forum (I think you want the last
post’s behaviour).

Best regards,

Axel

On Aug 19, 2008, at 6:20 PM, Matt H. wrote:

I think I want to be able to position the cursor back to the beginning
of the current line but I have no idea how to do this in ruby.

Grateful for any ideas

Thanks

Matt

In addition to print “\r” you might want to look at the docs for
ProgressBar

http://raa.ruby-lang.org/project/progressbar/

I can’t remember where I used this or I’d drop an example in here, but
it gives to a bar similar to what sftp or curl shows on downloads (it
even gives a time to complete estimate).

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Rob B. wrote:

line, “currentbytes/totalbytes [xx%]” and I want it to update the

In addition to print “\r” you might want to look at the docs for
ProgressBar

http://raa.ruby-lang.org/project/progressbar/

I can’t remember where I used this or I’d drop an example in here, but
it gives to a bar similar to what sftp or curl shows on downloads (it
even gives a time to complete estimate).

-Rob

Excellent, first I managed to get it working as I said in my post,
thanks to Axel’s link. Now I am trying the progress bar as Rob
suggested. It’s good but I can’t work out how the format is used.

I’m trying to expand the amount of text displayed in the title so I can
see the entire file and path.

Any extra help is appreciated but thanks for what you’ve done so far :wink:

Matt

On Aug 19, 2008, at 7:45 PM, Matt H. wrote:

-Rob
far :wink:

Matt

OK, here’s the context: getting CSV files from a url and saving them
locally

begin
File.open(csvfile, ‘w’) do |csvout|
pbar = nil
pbar_options = $stdout.tty? ? {
:content_length_proc => lambda {|t|
if t && 0 < t
pbar = ProgressBar.new(csvfile, t)
pbar.file_transfer_mode
end
},
:progress_proc => lambda {|s|
pbar.set s if pbar
},
} : { }
open(url, pbar_options) do |csvurl|
csvout.write csvurl.read
end
end # unless File.exist?(csvfile)
rescue => e
puts “\n** #{e}; #{e.message}”
puts " skipping file"
next
end

(I’m not boring you with all the setup to figure out the url and the
subsequent processing of the CSV data into a database.)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]