#!/usr/bin/perl
my
$quit
= AnyEvent->condvar;
sub
finger {
my
$user
=
shift
;
my
$host
=
shift
;
my
$fh
= new Coro::Socket
PeerHost
=>
$host
,
PeerPort
=>
"finger"
or
die
"$user\@$host: $!"
;
print
$fh
"$user\n"
;
print
"$user\@$host: $_"
while
<
$fh
>;
print
"$user\@$host: done\n"
;
}
async {
my
$w
= Coro::Event->timer (
interval
=> 0.001,
hard
=> 1);
while
() {
$w
->
next
;
print
"\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time "
,
time
,
"> \e8"
;
};
};
my
$stdin
= new_from_fh Coro::Handle \
*STDIN
;
$SIG
{PIPE} =
'IGNORE'
;
$| = 1;
while
() {
print
"cmd (finger|quit)> "
;
my
$cmd
= <
$stdin
>;
chomp
$cmd
;
if
(
$cmd
eq
"finger"
) {
print
"user> "
;
my
$user
= <
$stdin
>;
chomp
$user
;
print
"host> "
;
my
$host
= <
$stdin
>;
chomp
$host
;
async { finger
$user
,
$host
};
}
elsif
(
$cmd
eq
"quit"
) {
last
;
}
else
{
print
"unknown command '$cmd', either 'finger' or 'quit'\n"
;
}
}