1 | #!/usr/local/bin/perl -w |
---|
2 | |
---|
3 | use IO::Socket; |
---|
4 | use 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 | |
---|
18 | sleep 1; # Give server plenty of time to notice us... |
---|
19 | |
---|
20 | print $remote "hello\n"; |
---|
21 | my $lcdconnect = <$remote>; |
---|
22 | #print $lcdconnect; |
---|
23 | |
---|
24 | |
---|
25 | # Turn off blocking mode... |
---|
26 | fcntl($remote, F_SETFL, O_NONBLOCK); |
---|
27 | |
---|
28 | |
---|
29 | # Set up some screen widgets... |
---|
30 | print $remote "client_set name {fortune.pl}\n"; |
---|
31 | print $remote "screen_add fortune\n"; |
---|
32 | print $remote "screen_set fortune name {Fortune}\n"; |
---|
33 | print $remote "widget_add fortune title title\n"; |
---|
34 | print $remote "widget_set fortune title {Fortune}\n"; |
---|
35 | print $remote "widget_add fortune text scroller\n"; |
---|
36 | |
---|
37 | |
---|
38 | &update_text(); |
---|
39 | |
---|
40 | # Forever, we should do stuff... |
---|
41 | while(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 | |
---|
63 | close ($remote) || die "close: $!"; |
---|
64 | exit; |
---|
65 | |
---|
66 | sub 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 | } |
---|