File: async

package info (click to toggle)
libcdk-perl 20240606-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,732 kB
  • sloc: perl: 6,146; sh: 3,599; makefile: 28
file content (104 lines) | stat: -rwxr-xr-x 2,044 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl -w
# $Id: async,v 1.4 2013/07/17 19:34:06 tom Exp $

#
# This demo demonstrates how to use async functions with Cdk...
#

use strict;

#
# Initialize Cdk.
#
use Cdk;
Cdk::init();

# Set the async function...
$SIG{'ALRM'} = "littleWeeClock";

our @listItems;

# Set up the scrolling list.
setpwent();
while ( my $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( 'Message' => ["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 {

    #
    # Turn off the alarm
    #
    $SIG{'ALRM'} = "IGNORE";
    alarm(0);

    #
    # 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( 'Message' => ["Current Time: </B/$sec>$mesg"] );

    #
    # Reset the alarm.
    #
    $SIG{'ALRM'} = "littleWeeClock";
    alarm(1);
}