Changeset 73 for trunk/cuirc/cuirc

Show
Ignore:
Timestamp:
05/09/08 18:50:16 (8 months ago)
Author:
scott
Message:

Many bug fixes for CuIRC

  • Connecting now doesn't require two attempts.
  • ParseConfig? is now imported.
  • Debug logging added.
  • Fixed some of the ugly all caps-ness
  • Whois made into a dialog window.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/cuirc/cuirc

    r9 r73  
    1919use Text::Wrap (); 
    2020use Term::ANSIColor ":constants"; 
    21 use Config::General; 
     21use Config::General qw( ParseConfig ); 
    2222 
    2323my %opt; 
     
    3535 
    3636use constant { 
     37    DEBUG  => 1, 
    3738    ACTIVE => 0, 
    3839}; 
     
    4647    local $Text::Wrap::columns = $width; 
    4748    return split /\n/, Text::Wrap::wrap(undef, "    ", $string); 
     49} 
     50 
     51if (DEBUG) { 
     52    open LOG, ">>", "cuirc-debug.log"; 
     53    # Try to put errors in the window... 
     54    $SIG{"__DIE__"} = sub { 
     55        print LOG $_[0]; 
     56    }; 
     57    $SIG{"__WARN__"} = sub { 
     58        print LOG $_[0]; 
     59    }; 
    4860} 
    4961 
     
    8294                    $kernel->post($hostname, register => "all"); 
    8395                } 
    84                 else { 
    85                     $kernel->post(  
    86                         $hostname => connect => { 
    87                             Nick        => cuserid, 
    88                             Server      => $hostname, 
    89                             Port        => $port, 
    90                             Username    => cuserid, 
    91                             Ircname     => +(getpwnam cuserid)[6], 
    92                         }  
    93                     );  
    94                 } 
     96                 
     97                $kernel->post(  
     98                    $hostname => connect => { 
     99                        Nick        => cuserid, 
     100                        Server      => $hostname, 
     101                        Port        => $port, 
     102                        Username    => cuserid, 
     103                        Ircname     => +(getpwnam cuserid)[6], 
     104                    }  
     105                );  
    95106 
    96107                $kernel->yield 
     
    349360        )->focus; 
    350361 
    351         my (%Channel, $Current, @History, $CurCon, $CurrentChannel); 
     362        my (%Channel, $current, @history, $CurCon, $currentChannel); 
     363 
     364        $current = 0; 
    352365 
    353366        # The indirect method syntax isn't necessarily the best, but it does 
     
    358371            my $line = $input->get; 
    359372 
    360             push @History, $line; 
    361             $Current = @History; 
     373            push @history, $line; 
     374            $current = @history; 
    362375 
    363376            $input->text(""); 
     
    435448        }, "\t"; 
    436449         
    437                 set_binding $editor sub { 
    438                         shift->text($History[--$Current])  
     450        set_binding $editor sub { 
     451            shift->text($history[--$current]) if $current > 0; 
    439452        }, KEY_UP; 
    440453 
    441454        set_binding $editor sub { 
    442             $Current++; 
    443             if ($Current > @History) {  
    444                                 shift->text ("")  
    445                         }  
    446                         else { 
    447                                 shift->text ($History[$Current])  
    448                         } 
     455            $current++; 
     456            if ($current > @history) {  
     457                shift->text("")  
     458            }  
     459            else { 
     460                shift->text($history[$current])  
     461            } 
    449462        }, KEY_DOWN; 
    450463 
     
    534547 
    535548        # DRY - All these events go to the active window... (whois) 
    536         $kernel->state( "irc_$_" => sub { 
    537                 $_[KERNEL]->yield(write => active => $_[ARG1]); 
    538         } ) for qw( 311 312 313 314 315 316 317 318 319 ); 
     549        # Whois now results in a popup, badass. 
     550#       $kernel->state( "irc_$_" => sub { 
     551#               $_[KERNEL]->yield(write => active => $_[ARG1]); 
     552#       } ) for qw( 311 312 313 314 315 316 317 318 319 ); 
     553 
     554        # Do nothing for the following events...(whois) 
     555        # Whois is collected and displayed in a status window 
     556        $kernel->state( "irc_$_" => sub {} ) for 
     557            qw( 311 312 313 314 315 316 317 318 319 320  
     558                    irc_ctcp ); 
    539559    }, 
    540560 
     
    591611 
    592612        if ($type eq "channel") { 
    593             $screen->add ( 
    594                         "nicklist", 'Listbox', 
     613            my $nicklist = $screen->add( 
     614                "nicklist", 'Listbox', 
    595615                -x            => -1, 
    596616                -y            => -1, 
     
    601621                -intellidraw  => 1, 
    602622                ); 
     623 
     624            set_binding $nicklist sub { 
     625                my $nick = $nicklist->get_active_value; 
     626                # Remove op symbols and stuff. 
     627                $nick =~ s/^[@+]//; 
     628 
     629                my ($server) = ($name =~ m/(\S+)/); 
     630 
     631                $poe_kernel->yield(window_open => query => "$server $nick", 
     632                        "Query with $nick"); 
     633            }, BUTTON1_DOUBLE_CLICKED; 
    603634        } 
    604635 
     
    747778                  "Window $window has no nick list..." ); 
    748779        } 
     780    }, 
     781 
     782    # Get a whois event. 
     783    irc_whois => sub { 
     784        my ($kernel, $curses, $whois) = @_[ KERNEL, HEAP, ARG0 ]; 
     785 
     786        warn "Got whois event"; 
     787 
     788        # It's just too much work right here... 
     789        no warnings; 
     790 
     791        my $idle = $whois->{idle} ? ": ($whois->{idle}s idle)" : ""; 
     792        my $since = $whois->{signon} ?  
     793            "since " . scalar localtime $whois->{signon} : ""; 
     794 
     795        my $msg = <<WHOIS; 
     796$whois->{user}\@$whois->{host} "$whois->{real}" 
     797@{$whois->{channels}} 
     798$whois->{server} $since$idle 
     799WHOIS 
     800        $curses->dialog( 
     801            -message => $msg, 
     802            -title   => "Whois $whois->{nick}" 
     803        ); 
    749804    }, 
    750805