Changeset 6e6ded7 for perlwrap.pm


Ignore:
Timestamp:
Feb 16, 2007, 1:37:49 AM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
0449730
Parents:
b6c067a
git-author:
Nelson Elhage <nelhage@mit.edu> (02/16/07 01:37:35)
git-committer:
Nelson Elhage <nelhage@mit.edu> (02/16/07 01:37:49)
Message:
Making the default style generic, by adding some methods to
BarnOwl::Message to get display values in a generic way.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlwrap.pm

    rb6c067a r6e6ded7  
    204204}
    205205
     206# Display fields -- overridden by subclasses when needed
     207sub login_type {""}
     208sub login_extra {""}
     209sub long_sender {""}
     210
     211# The context in which a non-personal message was sent, e.g. a chat or
     212# class
     213sub context {""}
     214
     215# Some indicator of context *within* $self->context. e.g. the zephyr
     216# instance
     217sub subcontext {""}
     218
    206219#####################################################################
    207220#####################################################################
     
    238251
    239252use base qw( BarnOwl::Message );
     253
     254sub login_type {
     255    return (shift->zsig eq "") ? "(PSEUDO)" : "";
     256}
     257
     258sub login_extra {
     259    my $m = shift;
     260    return undef if (!$m->is_loginout);
     261    my $s = lc($m->host);
     262    $s .= " " . $m->login_tty if defined $m->login_tty;
     263    return $s;
     264}
     265
     266sub long_sender {
     267    my $m = shift;
     268    return $m->zsig;
     269}
     270
     271sub context {
     272    return shift->class;
     273}
     274
     275sub subcontext {
     276    return shift->instance;
     277}
    240278
    241279sub login_tty {
     
    483521    my $m = shift;
    484522
    485     if ( $m->is_zephyr ) {
    486         return format_zephyr($m);
    487     }
    488     elsif ( $m->is_admin ) {
     523    if ( $m->is_loginout) {
     524        return format_login($m);
     525    } elsif($m->is_ping) {
     526        return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
     527    } elsif($m->is_admin) {
    489528        return "\@bold(OWL ADMIN)\n" . indentBody($m);
    490     }
    491     elsif ( $m->is_aim ) {
    492         return format_aim($m);
    493     }
    494     elsif ( lc( $m->type ) eq 'loopback' ) {
    495         return format_loopback($m);
    496     }
    497     else {
    498         return "Unexpected message type.";
     529    } else {
     530        return format_chat($m);
    499531    }
    500532}
     
    503535
    504536################################################################################
    505 sub format_zephyr($)
    506 {
    507     my $m = shift;
    508 
    509     # Extract time from message
     537
     538sub time_hhmm {
     539    my $m = shift;
    510540    my ($time) = $m->time =~ /(\d\d:\d\d)/;
    511 
    512     # Deal with PING messages, assuming owl's rxping variable is true.
    513     if ( $m->is_ping && $m->recipient ne "" ) {
    514         return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
    515     }
    516 
    517     # Deal with login/logout messages
    518     elsif ( $m->is_loginout ) {
    519         return sprintf(
    520             '@b<%s%s> for @b(%s) at %s %s %s',
    521             uc( $m->login ),
    522 
    523             # This is a hack, owl does not export "pseudo"-ness
    524             ( $m->zsig ) ? "" : " (PSEUDO)",
    525             $m->pretty_sender,
    526             lc( $m->host ),
    527             $m->login_tty,
    528             $time
    529         );
    530     }
    531 
    532     # Deal with outbound zephyrs (personal, we don't see outbound non-personal)
    533     elsif ( lc( $m->direction ) eq 'out' ) {
    534         my $user = $m->recipient;
    535         $user =~ s/\@ATHENA[.]MIT[.]EDU$//;
    536 
    537         my $zsig = $m->zsig;
    538         $zsig =~ s/\n.*$//s;
    539 
    540         return sprintf( "Zephyr sent to %s  %s  (Zsig: %s)\n%s",
    541             $user, $time, $zsig, indentBody($m) );
    542     }
    543 
    544     # Deal with everything else
    545     else {
    546         my $zsig = $m->zsig;
    547         $zsig =~ s/\n.*$//s;
    548 
    549         my $msg = sprintf(
    550             "%s / %s / \@b<%s>%s  %s    (%s)\n%s",
    551             $m->class, $m->instance, $m->pretty_sender,
    552             ( $m->opcode ? " [@{[$m->opcode]}]" : "" ),
    553             $time, $zsig, indentBody($m)
    554         );
    555         return BarnOwl::Style::boldify($msg) if ( $m->is_private );
    556         return $msg;
    557     }
    558 }
    559 
    560 
    561 sub format_aim($)
    562 {
    563     my $m = shift;
    564 
    565     # Extract time from message
    566     my ($time) = $m->time =~ /(\d\d:\d\d)/;
    567 
    568     # Deal with login/logout messages
    569     if ( $m->is_loginout ) {
    570         return
    571           sprintf( "\@b(AIM %s) for %s %s",
    572                    uc( $m->login ),
    573                    $m->sender,
    574                    $time );
    575     }
    576     elsif ( lc( $m->direction ) eq 'out' ) {
    577         return sprintf( "AIM sent to %s  %s\n%s",
    578                         $m->recipient,
    579                         $time,
    580                         indentBody($m) );
    581     }
    582     else {
    583         return sprintf( "\@b(AIM from %s)  %s\n%s",
    584                         $m->sender,
    585                         $time,
    586                         BarnOwl::Style::boldify( indentBody($m) ) );
    587     }
    588 }
    589 
    590 
    591 sub format_loopback($)
    592 {
    593     my $m = shift;
    594 
    595     # Extract time from message
    596     my ($time) = $m->time =~ /(\d\d:\d\d)/;
    597 
    598     return sprintf( "loopback from: %s to: %s  %s\n%s",
    599         $m->sender, $m->recipient, $time, indentBody($m) );
    600 }
    601 
     541    return $time;
     542}
     543
     544sub format_login($) {
     545    my $m = shift;
     546    return sprintf(
     547        '@b<%s%s> for @b(%s) (%s) %s',
     548        uc( $m->login ),
     549        $m->login_type,
     550        $m->pretty_sender,
     551        $m->login_extra,
     552        time_hhmm($m)
     553       );
     554}
     555
     556sub format_chat($) {
     557    my $m = shift;
     558    my $header;
     559    if ( $m->is_personal ) {
     560        if ( $m->direction eq "out" ) {
     561            $header = ucfirst $m->type . " sent to " . $m->pretty_recipient;
     562        } else {
     563            $header = ucfirst $m->type . " from " . $m->pretty_sender;
     564        }
     565    } else {
     566        $header = $m->context;
     567        if($m->subcontext) {
     568            $header .= " / " . $m->subcontext;
     569        }
     570        $header .= " / " . $m->pretty_sender;
     571    }
     572
     573    $header .= "  " . time_hhmm($m);
     574    $header .= "\t(" . $m->long_sender . ")";
     575    my $message = $header . "\n". indentBody($m);
     576    if($m->is_private && $m->direction eq "in") {
     577        $message = BarnOwl::Style::boldify($message);
     578    }
     579    return $message;
     580}
    602581
    603582sub indentBody($)
Note: See TracChangeset for help on using the changeset viewer.