line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Tel::Color::Base; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 name |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
App::Tel::Color::Base - parent stub and examples for Color modules |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1965
|
use Term::ANSIColor; |
|
2
|
|
|
|
|
4912
|
|
|
2
|
|
|
|
|
94
|
|
10
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
28
|
|
11
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
493
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$Term::ANSIColor::AUTORESET++; # reset color after each print |
16
|
|
|
|
|
|
|
$SIG{INT} = sub { print "\n"; exit; }; # reset color after Ctrl-C |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @colors = qw ( GREEN YELLOW BLUE MAGENTA CYAN WHITE ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Bright colors were added after Term::ANSIColor 3.00 |
21
|
|
|
|
|
|
|
if ($Term::ANSIColor::VERSION >= 3.00) { |
22
|
|
|
|
|
|
|
push(@colors, qw ( |
23
|
|
|
|
|
|
|
BRIGHT_GREEN BRIGHT_YELLOW |
24
|
|
|
|
|
|
|
BRIGHT_BLUE BRIGHT_MAGENTA BRIGHT_CYAN BRIGHT_WHITE |
25
|
|
|
|
|
|
|
)); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 METHODS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $colorobject = new App::Tel::Base; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Initializes a new color object. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
6
|
|
|
6
|
1
|
2514
|
my $proto = shift; |
42
|
6
|
|
33
|
|
|
24
|
my $class = ref($proto) || $proto; |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
18
|
return bless( { }, $class); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 colorize |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $output = $colorobject->colorize('text'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Normally this will consume text from an input buffer and have some logic that |
52
|
|
|
|
|
|
|
determines how it will color the output. This method is designed to be |
53
|
|
|
|
|
|
|
overridden in all child modules. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
0
|
sub colorize { undef } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 parse |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$colorobject->parse($buffer, $callback); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Breaks a string up into substrings by line. It then calls colorize with the |
64
|
|
|
|
|
|
|
substring. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub parse { |
69
|
11
|
|
|
11
|
1
|
3758
|
my ($self, $buffer) = @_; |
70
|
11
|
|
|
|
|
11
|
my $output = ''; |
71
|
|
|
|
|
|
|
|
72
|
11
|
|
|
|
|
9
|
while(1) { |
73
|
29
|
|
|
|
|
21
|
my $string; |
74
|
|
|
|
|
|
|
# what about final lines that don't end in \r? Need to check this.. |
75
|
29
|
100
|
|
|
|
171
|
if($buffer =~ /^(.*?[\x0d\x0a]{1,2})/s) { |
76
|
18
|
|
|
|
|
52
|
$string = substr($buffer,0,length $1,''); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
29
|
100
|
|
|
|
44
|
last unless $string; |
80
|
18
|
|
|
|
|
36
|
$output .= $self->colorize($string); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
11
|
100
|
|
|
|
18
|
if (length $buffer) { |
84
|
10
|
|
|
|
|
25
|
$output .= $self->colorize($buffer); |
85
|
|
|
|
|
|
|
} |
86
|
11
|
|
|
|
|
26
|
return $output; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 get_colors |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my @colors = $self->get_colors(); |
92
|
|
|
|
|
|
|
my $color = $self->get_colors(1); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns a list of available colors by their names. This list excludes the RED |
95
|
|
|
|
|
|
|
color because it's used for errors and these colors are specifically for the |
96
|
|
|
|
|
|
|
rainbow code that doesn't use red. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
If given a value, it returns $color[value]. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_colors { |
103
|
17
|
100
|
|
17
|
1
|
49
|
$_[1] ? $colors[$_[1]] : @colors; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |