wiki:VtStyle

VT Style Display

Users of jervt transitioning to barnowl may find barnowl's default formatting to be wasteful of screen real estate, especially on wide terminals. With a few quick configuration changes, BarnOwl's display can be set to emulate vt's output fairly closely.

Style Template

Download the attached style template perl file and place it in your .owl directory.

Startup Script Updates

Append the following settings into your .owl/startup script (or create it if it doesn't exist):

#minimize the input space
set typewindelta 1
set typewinsize 1

#owl users prefer that zephyrs get sent in tiny chunks
set edit:maxwrapcols 80

#import the style template
perl do "~/.owl/styletemplate.pl"

#set the style template to be the default style.
set default_style mystyle

Comparison

No image "owlstyle.png" attached to VtStyle No image "vtstyle.png" attached to VtStyle

Inline Perl Script

perl script posted here due to wiki being busted

####################################################################
# 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
#

package BarnOwl::Style::MyStyle;
use List::Util qw[min max];
###############################################################################
# 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 $head;
    my $message;

    my $instance;

    my %short_classes = getShortClasses();
    if(defined $m->subcontext && (lc $m->subcontext ne "personal")) {
        $instance = $m->subcontext;
    }

    $head = substr($m->pretty_sender,0,9) . (" " x max(10 - (length $m->pretty_sender),1));
    my $midline;

    if($m->is_personal) {
        if($m->direction eq "out") {
            $midline = "->" . $m->pretty_recipient;
        } else {
            #no midline
        }
    } else {
        if(defined($short_classes{lc $m->context})) {
            $midline = (length($short_classes{$m->context}) > 0 ? '-' : '') . $short_classes{$m->context} . "." . $instance;
        } else {
            $midline = '-' . $m->context;
        }
    }

    if(defined $midline) {
        $head .= substr($midline,0,8) . (" " x max(9 - (length $midline),0)) . " ";
    }
 
    my $footer = "";
    if(defined $instance && !defined($short_classes{$m->context})) { 
        $footer .= '[' . $m->subcontext . ']'; 
    }
    $footer .= ' ' . time_hhmm($m);
    
    $message = $head . $m->body . $footer;
    $message = format_full_msg($head,$m,$footer);
    if($m->is_personal) {
        $message = BarnOwl::Style::boldify($message);
    }
    return $message;

}
#    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 getShortClasses{

    my %classes = (
        help => 'h',
        sipb => 's',
        message => ''
    );
}

sub format_full_msg
{
    my $h = shift;
    my $m = shift;
    my $f = shift;

    #output message
    my $message = "";

    # first, cleanup (de-rasterize) the body.
    my $cleanbody = $m->body;
    $cleanbody =~ s/\s/ /g;
    
    # now add the header right on there
    $cleanbody = $h . $cleanbody;
 
    # now we want to re-rasterize
    
    my $cols = BarnOwl::getnumcols() - 5;
  
    #temporary until the feeding is done by a seperate subprocess;
    my $indent = 0; 
    while (length($cleanbody) > 0 ) {
        
        my $line = (" " x $indent) . substr($cleanbody,0,$cols - $indent);
        $cleanbody = substr($cleanbody,$cols - $indent);
            
        if (length($cleanbody) > 0 ) {
            #normal run of the mill line.
            $message .= $line . "\n";
        }
        else {
            #last line. Attempt clean footer insertion
            if(length($line) + length($f) < $cols) {
                $message .= $line . fillWhiteSpace($cols,length($line) + length($f),$m) .  $f . "\n";
            } else {
                # The header adds too much space here to fit on one line. We want to
                # print out the full line, and then add the header on the next line.
                $message .= $line . "\n" . fillWhiteSpace($cols, length($f),$m) . $f . "\n"; 
            }
        }
        $indent = 2;
    }
    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;
}

sub fillWhiteSpace
{
    my $cols = shift;
    my $empty = shift;
    my $m = shift;
    
    my $output = "";
    my $length = $cols - $empty;

    if($m->long_sender eq "") {
        return $output = (" " x $length);
    }

    my $sig = $m->long_sender;
    $sig =~ s/\s/ /g;

    my $filler = " --" . $sig;

    $filler = (" " x max($length - (length $filler)-1,0)) . substr($filler,0,$length -1) . " ";
   
    $output = (" " x $length);
    if((length $filler) == (length $output)) {
        $output = $filler; 
    }
    return $output;
}

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

1;

Last modified 13 years ago Last modified on Nov 4, 2010, 2:09:35 PM