wiki:StyleTemplate

This is pretty out-of-date. It's from the old wiki. Anyone want to make a better version? VtStyle also has a copy of this.

####################################################################
# The code below is the same as the code used to define 
# the default style in barnowl.
# You can make a new, different-looking style by tweaking it.
# I'd recommend copying this and putting the file at
# ~/.owl/styletemplate.pl
# To use the new style in barnowl, use the following commands:
#
#perl do "/full/explicit/path/to/this/file/comma/namely/styletemplate.pl"
#view -s mystyle
#

#I might recommend binding keys in the recv keymap for reloading the
#style file as you tweak it, and for viewing the style. To do that,
#you would put the following commands in your .owl/startup file:

#bindkey recv s command view -s mystyle
#bindkey recv S command perl do "/full/explicit/path/to/this/file/comma/namely/styletemplate.pl"

#You could bind a key to return you to the default view with this line
#in your .owl/startup file:

#bindkey recv t command view -s default

#or, you could get back to the default style by pressing 'o' to toggle
#to the oneline style and then back to the default style.


###########################################################################
###########################################################################

package BarnOwl::Style::MyStyle;
###############################################################################
# Branching point for various formatting functions in this style.
###############################################################################
sub format_message($)
{
    my $m = shift;

    if ( $m->is_loginout) {
        return format_login($m);
    } elsif($m->is_ping) {
        return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
    } elsif($m->is_admin) {
        return "\@bold(OWL ADMIN)\n" . indentBody($m);
    } else {
        return format_chat($m);
    }
}



################################################################################

sub time_hhmm {
    my $m = shift;
    my ($time) = $m->time =~ /(\d\d:\d\d)/;
    return $time;
}

sub format_login($) {
    my $m = shift;
    return sprintf(
        '@b<%s%s> for @b(%s) (%s) %s',
        uc( $m->login ),
        $m->login_type,
        $m->pretty_sender,
        $m->login_extra,
        time_hhmm($m)
       );
}

sub format_chat($) {
    my $m = shift;
    my $header;
    if ( $m->is_personal ) {
        if ( $m->direction eq "out" ) {
            $header = ucfirst $m->type . " sent to " . $m->pretty_recipient;
        } else {
            $header = ucfirst $m->type . " from " . $m->pretty_sender;
        }
    } else {
        $header = $m->context;
        if(defined $m->subcontext) {
            $header .= ' / ' . $m->subcontext;
        }
        $header .= ' / @b{' . $m->pretty_sender . '}';
    }

    $header .= "  " . time_hhmm($m);
    my $sender = $m->long_sender;
    $sender =~ s/\n.*$//s;
    $header .= " " x (4 - ((length $header) % 4));
    $header .= "(" . $sender . ")";
    my $message = $header . "\n". indentBody($m);
    if($m->is_personal && $m->direction eq "in") {
        $message = BarnOwl::Style::boldify($message);
    }
    return $message;
}

sub indentBody($)
{
    my $m = shift;

    my $body = $m->body;
    # replace newline followed by anything with
    # newline plus four spaces and that thing.
    $body =~ s/\n(.)/\n    $1/g;

    return "    ".$body;
}


BarnOwl::command("style mystyle perl BarnOwl::Style::MyStyle::format_message");

1;
Last modified 11 years ago Last modified on Jan 19, 2013, 4:26:37 PM