line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::ANSIColor::Simple; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
842
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
820
|
use parent qw/Exporter/; |
|
1
|
|
|
|
|
324
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/color/; |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/c/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.10"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use overload |
13
|
1
|
|
|
1
|
|
1786
|
'""' => sub { shift->{string} }; |
|
1
|
|
|
0
|
|
1138
|
|
|
1
|
|
|
|
|
9
|
|
|
0
|
|
|
|
|
0
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %effects = ( |
16
|
|
|
|
|
|
|
'bold' => 1, |
17
|
|
|
|
|
|
|
'dark' => 2, |
18
|
|
|
|
|
|
|
'faint' => 2, |
19
|
|
|
|
|
|
|
'underline' => 4, |
20
|
|
|
|
|
|
|
'underscore' => 4, |
21
|
|
|
|
|
|
|
'blink' => 5, |
22
|
|
|
|
|
|
|
'reverse' => 7, |
23
|
|
|
|
|
|
|
'concealed' => 8, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %colors = ( |
27
|
|
|
|
|
|
|
'black' => 30, |
28
|
|
|
|
|
|
|
'red' => 31, |
29
|
|
|
|
|
|
|
'green' => 32, |
30
|
|
|
|
|
|
|
'yellow' => 33, |
31
|
|
|
|
|
|
|
'blue' => 34, |
32
|
|
|
|
|
|
|
'magenta' => 35, |
33
|
|
|
|
|
|
|
'cyan' => 36, |
34
|
|
|
|
|
|
|
'white' => 37, |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
'bright_black' => 90, |
37
|
|
|
|
|
|
|
'bright_red' => 91, |
38
|
|
|
|
|
|
|
'bright_green' => 92, |
39
|
|
|
|
|
|
|
'bright_yellow' => 93, |
40
|
|
|
|
|
|
|
'bright_blue' => 94, |
41
|
|
|
|
|
|
|
'bright_magenta' => 95, |
42
|
|
|
|
|
|
|
'bright_cyan' => 96, |
43
|
|
|
|
|
|
|
'bright_white' => 97, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my %grounds = ( |
47
|
|
|
|
|
|
|
'on_black' => 40, |
48
|
|
|
|
|
|
|
'on_red' => 41, |
49
|
|
|
|
|
|
|
'on_green' => 42, |
50
|
|
|
|
|
|
|
'on_yellow' => 43, |
51
|
|
|
|
|
|
|
'on_blue' => 44, |
52
|
|
|
|
|
|
|
'on_magenta' => 45, |
53
|
|
|
|
|
|
|
'on_cyan' => 46, |
54
|
|
|
|
|
|
|
'on_white' => 47, |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
'on_bright_black' => 100, |
57
|
|
|
|
|
|
|
'on_bright_red' => 101, |
58
|
|
|
|
|
|
|
'on_bright_green' => 102, |
59
|
|
|
|
|
|
|
'on_bright_yellow' => 103, |
60
|
|
|
|
|
|
|
'on_bright_blue' => 104, |
61
|
|
|
|
|
|
|
'on_bright_magenta' => 105, |
62
|
|
|
|
|
|
|
'on_bright_cyan' => 106, |
63
|
|
|
|
|
|
|
'on_bright_white' => 107, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my %all = (%effects, %colors, %grounds); |
67
|
|
|
|
|
|
|
my @colors_keys = keys %colors; |
68
|
|
|
|
|
|
|
my $colors_num = scalar @colors_keys; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
while ( my ($color, $code) = each %all ) { |
71
|
1
|
|
|
1
|
|
208
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
327
|
|
72
|
|
|
|
|
|
|
*{__PACKAGE__ . '::' . $color} = sub { |
73
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
74
|
0
|
|
|
|
|
0
|
$self->{string} = "\e[${code}m" . $self->{string} . "\e[0m"; |
75
|
0
|
|
|
|
|
0
|
return $self; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new { |
80
|
1
|
|
|
1
|
0
|
3
|
my ($class, $string) = @_; |
81
|
1
|
|
|
|
|
7
|
return bless +{ string => $string }, $class; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub c { |
85
|
0
|
|
|
0
|
0
|
0
|
my ($string) = @_; |
86
|
0
|
|
|
|
|
0
|
return __PACKAGE__->new($string); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub color { |
90
|
1
|
|
|
1
|
0
|
9
|
my ($string) = @_; |
91
|
1
|
|
|
|
|
10
|
return __PACKAGE__->new($string); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub rainbow { |
95
|
1
|
|
|
1
|
0
|
22
|
my $self = shift; |
96
|
1
|
|
|
|
|
169
|
my @chars = split //, $self->{string}; |
97
|
1
|
|
|
|
|
10
|
my @colored; |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
3
|
for my $char (@chars) { |
100
|
337
|
|
|
|
|
509
|
my $code = $colors{ $colors_keys[ int rand($colors_num) ] }; |
101
|
|
|
|
|
|
|
# other than spaces |
102
|
337
|
100
|
|
|
|
811
|
$code = 0 if $char =~ /\s/; |
103
|
337
|
|
|
|
|
693
|
push(@colored, "\e[${code}m$char\e[0m"); |
104
|
|
|
|
|
|
|
} |
105
|
1
|
|
|
|
|
71
|
return join '', @colored; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |