Re: Options for control of output in Terminal?

2004-11-22 Thread wren argetlahm
--- Bruce Van Allen <[EMAIL PROTECTED]> wrote:
> For your use, what you especially want to get from
> this example is the use of the Perl character "\b",
> which outside of regular expressions means "
> backspace". The point is to print "\b" the same 
> number of times as the number of characters you
> want to back up before printing the updated output.

Just an FYI if using this process (print
"\b"x$length), it's frequently good to put a sleep(1)
in there. Otherwise I've found that some glitchiness
can occour (with things not being completely deleted
before printing starts and vice-versa). I haven't
tested the specific code given which may be better
than a similar thing I have used, and sleep() may not
suit your purposes, but just figured I'd give a heads
up.

live well,
~wren



__ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 



Re: Options for control of output in Terminal?

2004-11-22 Thread Bruce Van Allen
On 2004-11-22 Dan Buettner wrote:
>Ideally, I'd like to have the window have a fixed display (no
>scrolling) and always output the information from a specific thread in
>a specific position.  In other words, Thread 1 gets the first 2 lines,
>Thread 2 gets lines 3 and 4, etc.

Maybe you could extrapolate from this, a simplified version of a
subroutine in my own local ::Utils module. The subroutine make_counter()
takes two arguments, a fixed initial part, here called $label, and a
starting number. It returns a closure that you use inside your loop. 

Note the $|++, which assures immediate output (to the terminal screen).

For your use, what you especially want to get from this example is the
use of the Perl character "\b", which outside of regular expressions
means "backspace". The point is to print "\b" the same number of times
as the number of characters you want to back up before printing the
updated output. I believe you should be able to stack fixed and varying
lines with a little practice...

#!/usr/bin/perl

# trivial_count.pl
 
use strict;
use warnings;

$|++;

my $max = $ARGV[0] || 1;

print "Searching...\n";

my $counter = make_counter("Here's how many I've found: "); 

for (1..$max) {
print $counter->() 
}

print "\n";

sub make_counter {
my ($label,$start)  = @_;
$label  ||= 'Count:';
my $count   = $start ||= 1;
my $flag= 1;
return sub {
$flag ? 
   $flag-- && "$label  " . $count :
   "\b" x length($count) . ++$count;
}
}
__END__


bva$ perl /Volumes/Programming/trivial_count.pl 678
Searching...
Here's how many I've found:   678
bva$ 



HTH

- Bruce

__bruce__van_allen__santa_cruz__ca__


Re: Options for control of output in Terminal?

2004-11-22 Thread Sherm Pendley
On Nov 22, 2004, at 5:20 PM, Dan Buettner wrote:
How could I put information into a static display like this?
Have a look at the Curses module on CPAN.
sherm--


Options for control of output in Terminal?

2004-11-22 Thread Dan Buettner
I'm working on a multithreaded perl script that will have a group of 
threads uploading files via FTP.

I'd like to have each thread display status information in the 
Terminal window, e.g.:

Terminal-
Thr1  16:12:07: Uploading 'mysamplefile' (890.0 KB) to 'myhost.com'
##
Thr2  16:10:07: Uploading 'myBIGsamplefile' (99.1 MB) to 'myhost.com'
#
Thr3  16:05:08: Uploaded 'lastfile' (5.1 MB) to 'ftpserver.com'
Thr4  16:13:06: Uploading littlefile' (44.8 KB) to 'anotherhost.com'
##
-
The # symbols above would be the hash output from Net::FTP as it uploads ...
Ideally, I'd like to have the window have a fixed display (no 
scrolling) and always output the information from a specific thread 
in a specific position.  In other words, Thread 1 gets the first 2 
lines, Thread 2 gets lines 3 and 4, etc.

The script right now is not threaded, and using the hash output from 
Net::FTP works great - divide filesize by 100 and set that to your 
hash value to get a great text-based progress bar.

How could I put information into a static display like this?  And 
could I still use the Net::FTP progress bar?

Suggestions appreciated.
Thanks,
Dan