[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

overprinting characters

Matt Harrison

8/19/2008 10:21:00 PM

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

5 Answers

Michael W. Ryder

8/19/2008 11:16:00 PM

0

Matt Harrison wrote:
> 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.

Axel Etzold

8/19/2008 11:19:00 PM

0


-------- Original-Nachricht --------
> Datum: Wed, 20 Aug 2008 07:20:58 +0900
> Von: Matt Harrison <iwasinnamuknow@genestate.com>
> An: ruby-talk@ruby-lang.org
> 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/... (I think you want the last post's behaviour).

Best regards,

Axel

--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_...

Rob Biedenharn

8/19/2008 11:24:00 PM

0


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

> 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/pr...

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://agileconsult...
Rob@AgileConsultingLLC.com



Matt Harrison

8/19/2008 11:46:00 PM

0

Rob Biedenharn wrote:
>
> On Aug 19, 2008, at 6:20 PM, Matt Harrison wrote:
>
>> 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/pr...
>
> 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

Rob Biedenharn

8/20/2008 3:59:00 AM

0


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

>> In addition to print "\r" you might want to look at the docs for
>> ProgressBar
>>
>> http://raa.ruby-lang.org/project/pr...
>>
>> 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


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://agileconsult...
Rob@AgileConsultingLLC.com