ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-IRC3/samples/jsonclient
Revision: 1.2
Committed: Wed Dec 6 23:08:51 2006 UTC (19 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.1: +54 -146 lines
Log Message:
refactored the main gui for the curses client.
input line and the main window work now finally,
even scrolling with page up and page down works now.

File Contents

# User Rev Content
1 elmex 1.1 #!/usr/bin/perl
2     use strict;
3     use JSONConnection;
4 elmex 1.2 use POSIX qw(strftime);
5     use CursesChatMainwindow;
6 elmex 1.1
7 elmex 1.2 our $connections;
8     our $buffer_counter = 0;
9     our $known_channels;
10 elmex 1.1
11     our $js;
12    
13 elmex 1.2 my $c = AnyEvent->condvar;
14 elmex 1.1
15     my $d = 0;
16     my $wt;
17     sub timer {
18     $wt = AnyEvent->timer (after => 3, cb => sub {
19 elmex 1.2 printline (status => [0, "TEST $d"]); $d++;
20 elmex 1.1 timer ();
21     });
22     }
23 elmex 1.2 #timer ();
24 elmex 1.1
25     $js =
26     JSONClientConnection->new (packet_cb => sub {
27     my ($js, $data) = @_;
28     require JSON::Syck;
29 elmex 1.2 if ($data->{type} eq 'channels') {
30     $connections = $data->{connections};
31     for my $host (keys %$connections) {
32     for my $channel (@{$connections->{$host}}) {
33     $known_channels->{"$buffer_counter"} = [$host, $channel];
34     printline (status => [0, "new buffer: $buffer_counter"]);
35     $buffer_counter++;
36     }
37     }
38     } elsif ($data->{type} eq 'public') {
39     my ($con, $chan) = ($data->{con}, $data->{channel});
40     my ($id) =
41     grep {
42     $known_channels->{$_}->[0] eq $con
43     and $known_channels->{$_}->[1] eq $chan
44     } keys %$known_channels;
45     my $ts = POSIX::strftime ("%T", localtime ($data->{timestamp}));
46     $ts = "[$ts] $data->{from}->{nick}> ";
47     my (@chatline) = (("p".length $ts), 0, "$ts$data->{message}");
48     printline (((defined $id) ? "$id" : 'status'), \@chatline);
49     printline (status => [0, "FOUND LINE: $id"]);
50     }
51     printline (status => [0, JSON::Syck::Dump ($data)]);
52 elmex 1.1 });
53    
54     $js->connect (localhost => 1236);
55    
56 elmex 1.2 CursesChatMainwindow::init;
57 elmex 1.1
58 elmex 1.2 printline (status => ['p0', 0, "Connected!fdweifoj wfiowj iof ejwiofe wfh weufh weiufwe1234567890"]);
59     printline (statusline => [20, "[#blob]"]);
60    
61     CursesChatMainwindow::register_input_cb (sub {
62     my ($input) = @_;
63     if ($input =~ m/^\/b\s*(\S+)/) {
64     if (exists $known_channels->{$1}) {
65     select_buffer ("$1");
66     printline (statusline => [21, "[$known_channels->{$1}->[1]]"]);
67     } else {
68     printline (status => [0, "no such buffer '$1'"]);
69 elmex 1.1 }
70 elmex 1.2 } elsif ($input =~ m/^\/colors/) {
71     CursesChatMainwindow::print_colors;
72     } else {
73     $js->send_data ({
74     type => 'public',
75     con => "localhost:6667",
76     channel => '#blob',
77     message => $input
78     });
79 elmex 1.1 }
80 elmex 1.2 });
81 elmex 1.1
82     $c->wait;
83    
84 elmex 1.2 CursesChatMainwindow::end;