source: npl/mediabox/lcdproc_edwin/src/clients/examples/fortune.pl

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 1.6 KB
Line 
1#!/usr/local/bin/perl -w
2
3use IO::Socket;
4use Fcntl;
5
6
7# Connect to the server...
8$remote = IO::Socket::INET->new(
9                Proto     => "tcp",
10                PeerAddr  => "localhost",
11                PeerPort  => "13666",
12        )
13        || die "Cannot connect to LCDproc port\n";
14
15# Make sure our messages get there right away
16$remote->autoflush(1);
17
18sleep 1;        # Give server plenty of time to notice us...
19
20print $remote "hello\n";
21my $lcdconnect = <$remote>;
22#print $lcdconnect;
23
24
25# Turn off blocking mode...
26fcntl($remote, F_SETFL, O_NONBLOCK);
27
28
29# Set up some screen widgets...
30print $remote "client_set name {fortune.pl}\n";
31print $remote "screen_add fortune\n";
32print $remote "screen_set fortune name {Fortune}\n";
33print $remote "widget_add fortune title title\n";
34print $remote "widget_set fortune title {Fortune}\n";
35print $remote "widget_add fortune text scroller\n";
36
37
38&update_text();
39
40# Forever, we should do stuff...
41while(1)
42{
43        # Handle input...  (spew it to the console)
44        # Also, certain keys scroll the display
45        while(defined($input = <$remote>)) {
46            #print $input;
47
48            # Make sure we handle each line...
49            @lines = split(/\n/, $input);
50            foreach $line (@lines)
51            {
52                if($line =~ /^ignore (\S)/)  # Update just after disappearing
53                {
54                    &update_text();
55                }
56            }
57        }
58
59        # And wait a little while before we check for input again.
60        sleep 1;
61}
62
63close ($remote)            || die "close: $!";
64exit;
65
66sub update_text {
67    # Grab some text.
68    $text = `fortune`;
69    @lines = split(/\n/, $text);
70    $text = join(" / ", @lines);
71   
72    # Now, show a fortune...
73    print $remote "widget_set fortune text 1 2 20 4 v 16 {$text}\n";
74
75}
Note: See TracBrowser for help on using the repository browser.