source: perl/lib/BarnOwl/Style/OneLine.pm @ bc8275e

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since bc8275e was ee183be, checked in by Nelson Elhage <nelhage@mit.edu>, 15 years ago
Break perlwrap.pm into multiple files. Break perlwrap.pm out into .pm files in perl/lib. With this commit, we keep perlwrap.pm around and still load it as before. The next commit will delete perlwrap.pm and start loading perl files directly from disk at runtime.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1use strict;
2use warnings;
3
4package BarnOwl::Style::OneLine;
5# Inherit format_message to dispatch
6our @ISA = qw(BarnOwl::Style::Default);
7
8use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s ';
9
10sub description {"Formats for one-line-per-message"}
11
12BarnOwl::create_style("oneline", "BarnOwl::Style::OneLine");
13
14################################################################################
15
16sub maybe {
17    my $thing = shift;
18    return defined($thing) ? $thing : "";
19}
20
21sub format_login {
22  my $self = shift;
23  my $m = shift;
24  return sprintf(
25    BASE_FORMAT,
26    '<',
27    $m->type,
28    uc( $m->login ),
29    $m->pretty_sender)
30    . ($m->login_extra ? "at ".$m->login_extra : '');
31}
32
33sub format_ping {
34  my $self = shift;
35  my $m = shift;
36  return sprintf(
37    BASE_FORMAT,
38    '<',
39    $m->type,
40    'PING',
41    $m->pretty_sender)
42}
43
44sub format_chat
45{
46  my $self = shift;
47  my $m = shift;
48  my $dir = lc($m->{direction});
49  my $dirsym = '-';
50  if ($dir eq 'in') {
51    $dirsym = '<';
52  }
53  elsif ($dir eq 'out') {
54    $dirsym = '>';
55  }
56
57  my $line;
58  if ($m->is_personal) {
59
60    # Figure out what to show in the subcontext column
61    $line= sprintf(BASE_FORMAT,
62                   $dirsym,
63                   $m->type,
64                   maybe($m->short_personal_context),
65                   ($dir eq 'out'
66                    ? $m->pretty_recipient
67                    : $m->pretty_sender));
68  }
69  else {
70    $line = sprintf(BASE_FORMAT,
71                    $dirsym,
72                    maybe($m->context),
73                    maybe($m->subcontext),
74                    ($dir eq 'out'
75                     ? $m->pretty_recipient
76                     : $m->pretty_sender));
77  }
78
79  my $body = $m->{body};
80  $body =~ tr/\n/ /;
81  $line .= $body;
82  return $line;
83}
84
85# Format owl admin messages
86sub format_admin
87{
88  my $self = shift;
89  my $m = shift;
90  my $line = sprintf(BASE_FORMAT, '<', 'ADMIN', '', '');
91  my $body = $m->{body};
92  $body =~ tr/\n/ /;
93  return $line.$body;
94}
95
96
971;
Note: See TracBrowser for help on using the repository browser.