Changeset ad0deddb4298f15386cb0fca17ff0b2265b9ba7d
- Timestamp:
- 10/28/09 10:00:15 (4 weeks ago)
- Author:
- Karl Ramm <kcr@1ts.org>
- git-author:
- Karl Ramm <kcr@1ts.org> / 2009-10-25T12:11:13Z-0400
- Parents:
- 7ca5d3e3f8c76c75f3200773de375d80ac951461
- Children:
- 48d130b1d845e04389262e8cbfdd3064726b9468
- git-committer:
- Karl Ramm <kcr@1ts.org> / 2009-10-28T10:00:15Z-0400
- Message:
-
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...
- Location:
- perl/lib/BarnOwl/Style
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r0b2afba
|
rad0dedd
|
|
| 24 | 24 | } |
| 25 | 25 | $fmt = BarnOwl::Style::boldify($fmt) if $self->should_bold($m); |
| | 26 | $fmt = $self->humanize($fmt); |
| 26 | 27 | return $fmt; |
| 27 | 28 | } |
| … |
… |
|
| 86 | 87 | if ( $m->is_personal ) { |
| 87 | 88 | my $personal_context = $m->personal_context; |
| 88 | | $personal_context = ' [' . $personal_context . ']' if $personal_context; |
| | 89 | $personal_context = ' [' . $self->humanize($personal_context, 1) . ']' if $personal_context; |
| 89 | 90 | |
| 90 | 91 | if ( $m->direction eq "out" ) { |
| … |
… |
|
| 94 | 95 | } |
| 95 | 96 | } else { |
| 96 | | $header = $m->context; |
| | 97 | $header = $self->humanize($m->context, 1); |
| 97 | 98 | if(defined $m->subcontext) { |
| 98 | | $header .= ' / ' . $m->subcontext; |
| | 99 | $header .= ' / ' . $self->humanize($m->subcontext, 1); |
| 99 | 100 | } |
| 100 | 101 | $header .= ' / @b{' . $m->pretty_sender . '}'; |
| … |
… |
|
| 102 | 103 | |
| 103 | 104 | if($m->opcode) { |
| 104 | | $header .= " [" . $m->opcode . "]"; |
| | 105 | $header .= " [" . $self->humanize($m->opcode, 1) . "]"; |
| 105 | 106 | } |
| 106 | 107 | $header .= " " . $self->format_time($m); |
| … |
… |
|
| 138 | 139 | } |
| 139 | 140 | |
| | 141 | =head3 humanize STRING [one_line] |
| | 142 | |
| | 143 | Method that takes a STRING with control characters and makes it human |
| | 144 | readable in such a way as to not do anything funky with the terminal. |
| | 145 | If one_line is true, be more conservative about what we treat as |
| | 146 | control character. |
| | 147 | |
| | 148 | =cut |
| | 149 | |
| | 150 | sub humanize |
| | 151 | { |
| | 152 | my $self = shift; |
| | 153 | my $s = shift; |
| | 154 | my $oneline = shift; |
| | 155 | sub _humanize_char |
| | 156 | { |
| | 157 | my $c = ord(shift); |
| | 158 | |
| | 159 | if ($c < ord(' ')) { |
| | 160 | return ('^' . chr($c + ord('@'))); |
| | 161 | } elsif ($c == 255) { |
| | 162 | return ('^?'); |
| | 163 | } else { |
| | 164 | return (sprintf('\\x{%x}', $c)); |
| | 165 | } |
| | 166 | } |
| | 167 | my $colorize = (BarnOwl::getvar('colorztext') eq 'on') |
| | 168 | ? '@color(cyan)' : ''; |
| | 169 | |
| | 170 | my $chars = $oneline ? qr/[[:cntrl:]]/ : qr/[^[:print:]]|[\r\cK\f]/; |
| | 171 | |
| | 172 | $s =~ s/($chars)/ |
| | 173 | "\@b($colorize" . _humanize_char($1) . ')'/eg; |
| | 174 | |
| | 175 | return $s; |
| | 176 | } |
| | 177 | |
| | 178 | =head3 humanize_short STRING |
| | 179 | |
| | 180 | As above, but always be conservative, and replace with a '?' instead |
| | 181 | of something mmore elaborate. |
| | 182 | |
| | 183 | =cut |
| | 184 | |
| | 185 | sub humanize_short |
| | 186 | { |
| | 187 | my $self = shift; |
| | 188 | my $s = shift; |
| | 189 | |
| | 190 | $s =~ s/[[:cntrl:]]/?/g; |
| | 191 | |
| | 192 | return $s; |
| | 193 | } |
| 140 | 194 | |
| 141 | 195 | 1; |
-
|
rfc92548d
|
rad0dedd
|
|
| 80 | 80 | $body =~ tr/\n/ /; |
| 81 | 81 | $line .= $body; |
| | 82 | $line = $self->humanize_short($line); |
| 82 | 83 | return $line; |
| 83 | 84 | } |