/usr/share/perl5/App/KGB/Painter.pm is in kgb-client 1.33-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | package App::KGB::Painter;
=head1 NAME
App::KGB::Painter -- add color to KGB notifications
=head1 DESCRIPTION
B<App::KGB::Painter> is a simple class encapsulating coloring of KGB messages.
=cut
use strict;
use warnings;
our $VERSION = 1.27;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors( qw(item_colors color_codes simulate) );
our %color_codes = (
bold => "\002", # ^B
normal => "\017", # ^O
underline => "\037", # ^_
reverse => "\026", # ^V
black => "\00301",
navy => "\00302",
green => "\00303",
red => "\00304",
brown => "\00305",
purple => "\00306",
orange => "\00307",
yellow => "\00308",
lime => "\00309",
teal => "\00310",
aqua => "\00311",
blue => "\00312",
fuchsia => "\00313",
silver => "\00314",
white => "\00316",
reset => "\017",
);
our %item_colors = (
revision => undef,
path => 'teal',
author => 'green',
branch => 'brown',
project => 'blue',
module => 'purple',
web => 'silver',
separator => undef,
addition => 'green',
modification => 'teal',
deletion => 'bold red',
replacement => 'brown',
prop_change => 'underline',
);
=head1 CONSTRUCTOR
=head2 new
my $p = App::KGB::Painter->new({ color_codes => { ... }, style => { ... } } );
B<color_codes> is a hash with the special symbols interpreted as coloring
commands by IRC clients.
B<style> is another hash describing what colors to apply to different parts of
the messages.
=cut
sub new {
my $self = shift->SUPER::new(@_);
# default colors
$self->color_codes( \%color_codes ) unless $self->color_codes;
my $c = $self->color_codes;
while ( my ($k,$v) = each %color_codes ) {
$c->{$k} = $v unless exists $c->{$k};
}
# default styles
$self->item_colors( \%item_colors ) unless $self->item_colors;
my $s = $self->item_colors;
while ( my ($k,$v) = each %item_colors ) {
$s->{$k} = $v unless exists $s->{$k};
}
return $self;
}
=head1 METHODS
=over
=item B<colorize> I<category> I<text>
Applies the colors of the style I<category> to the given I<text>.
=cut
sub colorize {
my ( $self, $category, $text ) = @_;
return $text if $self->simulate;
my $color = $self->item_colors->{$category};
unless ($color) {
warn
"Not coloring '$text' due to unknown color '$color' for category '$category'"
if 0;
return $text;
}
my $c = $self->color_codes;
for ( split( /\s+/, $color ) ) {
$text = $c->{$_} . $text if $c->{$_};
}
$text .= $c->{reset};
warn "Colored ($category/$color): $text" if 0;
return $text;
}
our %action_items = (
A => 'addition',
M => 'modification',
D => 'deletion',
R => 'replacement',
);
=item B<colorize_change> I<change>
Given a change, applies colors to its files depending on the type of the change
-- update, addition, deletion or property change.
=cut
sub colorize_change {
my $self = shift;
my $c = shift;
my $action_item = $action_items{ $c->action };
unless ($action_item) {
warn $c->action . " is an unknown action\n";
return $c->path;
}
my $text = $self->colorize( $action_item, $c->path );
$text = $self->colorize( 'prop_change', $text ) if $c->prop_change;
return $text;
}
=back
=head1 COPYRIGHT & LICENSE
Copyright (c) Damyan Ivanov <dmn@debian.org>.
This module is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
=cut
1;
|