#!../../../perl -w
#
# This demo demonstrates how to use async functions with Cdk...
#
#
# Initialize Cdk.
#
use Cdk;
Cdk::init();
# Set the async function...
$SIG{'ALRM'} = "littleWeeClock";
# Set up the scrolling list.
setpwent();
while ($item = getpwent())
{
push (@listItems, $item);
}
# Get the screen dimensions.
my ($rows, $cols) = Cdk::getCdkScreenDim ();
# Create the scrolling list object.
my $scroll = new Cdk::Scroll ('Title' => "<C></U/5>Pick An Account",
'Height' => 10,
'Numbers' => "TRUE",
'Highlight' => "</B/29>",
'Width' => 25,
'List' => \@listItems);
# Create the label...
my $clock = new Cdk::Label ('Mesg' => ["Current Time: HH:MM:SS"], 'Xpos' => "TOP");
# Draw the scrolling window.
$clock->draw();
# Set the alarm to go off.
alarm (1);
# Do this forever.
for (;;)
{
# Activate the scrolling list.
my $itemPicked = $scroll->activate();
# Do we need to exit...
exit if ! defined $itemPicked;
# Get the password info.
my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwnam ($listItems[$itemPicked]);
# Display it.
my $info = ["</B/5>Account Name<!B!5> $name",
"</B/5>UID <!B!5> $uid",
"</B/5>GID <!B!5> $gid",
"</B/5>Directory <!B!5> $dir",
"</B/5>Shell <!B!5> $shell"];
popupLabel ($info);
}
# Exit Cdk.
Cdk::end();
#
# This is the async function.
#
sub littleWeeClock
{
# Get the current time/date.
my ($sec, $min, $hour) = (localtime(time));
my $mesg = sprintf ("%02d:%02d:%02d", $hour, $min, $sec);
# Add the line to the scrolling window.
$clock->set ('Mesg' => ["Current Time: </B/$sec>$mesg"]);
# Reset the alarm.
alarm (1);
}