Article: 3228 of comp.lang.perl
Xref: feenix.metronet.com comp.lang.perl:3228
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.ecn.bgu.edu!wupost!howland.reston.ans.net!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!network.ucsd.edu!munnari.oz.au!cs.mu.OZ.AU!nareen.acci.COM.AU!ggr
From:
[email protected] (Greg Rose)
Subject: Re: Screen 'stuff'...
Message-ID: <
[email protected]>
Sender:
[email protected]
Organization: Australian Computing and Communications Institute
References: <
[email protected]> <
[email protected]>
Date: Mon, 7 Jun 1993 23:46:15 GMT
Lines: 100
In article <
[email protected]>
[email protected] (Jason Verch) writes:
>... You will have
>a program called curseperl, this is a version of perl that has curses
>functions built in, you can call them just like perl subroutines, i.e.
> &initscr;
>It seems to work fairly well so far, I havent played much yet... Does anyone
>have nifty examples of using curses calls in perl to share?
The following script is one of my favourites. When you have a program
which outputs something, and most of the information is constant, but
you want to watch what changes, you use this utility (which I call
'watch'). For example, suppose you are creating a large file, and you
want to monitor the progress of the growth, you could say:
watch ls -l bigfile
and see it happen. This is not a particularly good example, since in
this case there is only one line to watch, and you could just
repeatedly execute the ls command itself, but when the information
becomes multi-line, or the interesting part might move around, it
becomes a big win -- human eyes being attracted to movement as they
are.
Manual page? You can either give it a command to execute, or it will
read STDIN. In either case, a form feed character on input (preferably
on a line by itself, since the line is discarded) will update the
screen, and further input is considered to be more (slightly
different) of the same; this is for some older programs which ran
continuously and produced paginated output. More normally, the program
is run every $SLEEPTIME seconds, and the modifications apply to
successive runs. As a simple example, try 'watch date'. Program
terminates on terminate or interrupt signals.
Share and enjoy!
Greg Rose Australian Computing and Communications Institute
[email protected] +61 18 174 842
`Use of the standard phrase "HIJACKED" may be inadvisable' -- CAA
----------- cut cut cut -----------
#!/usr/local/bin/curseperl
# Watch the world go by
# Copyright C 1992 Australian Computing and Communications Institute Inc.
# Written by Greg Rose.
# Use it as you will, no warranties expressed or implied, leave
# this copyright statement intact.
$SLEEPTIME = 3; # seconds between executions
$SIG{TERM} = 'catchit';
$SIG{INT} = 'catchit';
sub catchit {
$caught = 1;
}
if (@ARGV) {
open(INFILE, "@ARGV|") || die "can't run @ARGV: $!\n";
} else {
open(INFILE, "<&STDIN") || die "can't dup stdin: $!\n";;
}
&initscr;
&refresh;
eval <<'END';
while (!$caught) {
&move(0,0);
$closeit = 1;
while (($_ = <INFILE>) && !$caught) {
if (//) {
$closeit = 0;
last;
}
&addstr($_);
}
last if $caught;
&clrtobot;
&refresh;
if ($closeit) {
close(INFILE);
last unless @ARGV;
sleep($SLEEPTIME);
open(INFILE, "@ARGV|") || die "can't run @ARGV: $!\n";
}
}
END
&move($LINES - 1,0);
&clrtoeol;
&refresh;
&endwin;
warn $@ if $@;
--
Greg Rose Australian Computing and Communications Institute
[email protected] +61 18 174 842
`Use of the standard phrase "HIJACKED" may be inadvisable' -- CAA