#----------------------------- |
#% rep ps aux |
#% rep netstat |
#% rep -2.5 lpq |
#----------------------------- |
# download the following standalone program |
#!/usr/bin/perl -w |
# rep - screen repeat command |
use strict; |
use Curses; |
my $timeout = 10; |
if ( @ARGV && $ARGV [0] =~ /^- ( \d+\.?\d* ) $/ ) |
{ |
$timeout = $1 ; |
shift ; |
} |
die "usage: $0 [ -timeout ] cmd args\n" unless @ARGV ; |
initscr(); |
# start screen |
noecho(); |
cbreak(); |
nodelay ( 1 ); |
# so getch() is non-blocking |
$SIG { INT } = sub { done ( "Ouch!" ) }; |
sub done { endwin(); print "@_\n" ; exit ; } |
while ( 1 ) |
{ |
while ( ( my $key = getch() ) ne ERR ) |
{ |
# maybe multiple keys |
done ( "See ya" ) if $key eq 'q' |
} |
my @data = ` ( @ARGV ) 2>&1`; |
# gather output+errors |
for ( my $i = 0; $i < $LINES ; $i ++ ) |
{ |
addstr ( $i , 0, $data [ $i ] || ' ' x $COLS ); |
} |
standout(); |
addstr ( $LINES -1, $COLS - 24, scalar localtime ); |
standend(); |
move ( 0,0 ); |
refresh(); |
# flush new output to display |
my ( $in , $out ) = ( '' , '' ); |
vec ( $in , fileno ( STDIN ),1 ) = 1; |
# look for key on stdin |
select ( $out = $in , undef , undef , $timeout ); |
# wait up to this long |
} |
#----------------------------- |
keypad ( 1 ); |
# enable keypad mode |
$key = getch(); |
if ( $key eq 'k' || # vi mode |
$key eq "\cP" || # emacs mode |
$key eq KEY_UP ) # arrow mode |
{ |
# do something |
} |
#----------------------------- |
# Template Entry Demonstration |
# |
# Address Data Example Record # ___ |
# |
# Name: [________________________________________________] |
# Addr: [________________________________________________] |
# City: [__________________] State: [__] Zip: [\\\\\] |
# |
# Phone: (\\\) \\\-\\\\ Password: [^^^^^^^^] |
# |
# Enter all information available. |
# Edit fields with left/right arrow keys or "delete". |
# Switch fields with "Tab" or up/down arrow keys. |
# Indicate completion by pressing "Return". |
# Refresh screen with "Control-L". |
# Abort this demo here with "Control-X". |
#----------------------------- |