overprinting characters

M

Matt Harrison

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
 
M

Michael W. Ryder

Matt said:
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
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.
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Wed, 20 Aug 2008 07:20:58 +0900
Von: Matt Harrison <[email protected]>
An: (e-mail address removed)
Betreff: 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

Dear Matt,

try this:

http://www.ruby-forum.com/topic/162334#new (I think you want the last post's behaviour).

Best regards,

Axel
 
R

Rob Biedenharn

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

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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
M

Matt Harrison

Rob said:
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

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 ;)

Matt
 
R

Rob Biedenharn

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 ;)

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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,053
Members
47,656
Latest member
rickwatson

Latest Threads

Top