release-1.10release-1.5release-1.6release-1.7release-1.8release-1.9
Last change
on this file since 6dba228 was
ad0dedd,
checked in by Karl Ramm <kcr@1ts.org>, 15 years ago
|
make control characters human-readable
Random control characters that make it through the formatting code
should not be passed silently to the user's terminal...
|
-
Property mode set to
100644
|
File size:
2.0 KB
|
Line | |
---|
1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::Style::OneLine; |
---|
5 | # Inherit format_message to dispatch |
---|
6 | use base qw(BarnOwl::Style::Default); |
---|
7 | |
---|
8 | use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s '; |
---|
9 | |
---|
10 | sub description {"Formats for one-line-per-message"} |
---|
11 | |
---|
12 | BarnOwl::create_style("oneline", "BarnOwl::Style::OneLine"); |
---|
13 | |
---|
14 | ################################################################################ |
---|
15 | |
---|
16 | sub maybe { |
---|
17 | my $thing = shift; |
---|
18 | return defined($thing) ? $thing : ""; |
---|
19 | } |
---|
20 | |
---|
21 | sub 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 | |
---|
33 | sub 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 | |
---|
44 | sub 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 | $line = $self->humanize_short($line); |
---|
83 | return $line; |
---|
84 | } |
---|
85 | |
---|
86 | # Format owl admin messages |
---|
87 | sub format_admin |
---|
88 | { |
---|
89 | my $self = shift; |
---|
90 | my $m = shift; |
---|
91 | my $line = sprintf(BASE_FORMAT, '<', 'ADMIN', '', ''); |
---|
92 | my $body = $m->{body}; |
---|
93 | $body =~ tr/\n/ /; |
---|
94 | return $line.$body; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.