line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::ExtendedColor::TTY; |
2
|
2
|
|
|
2
|
|
130494
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
68
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
2
|
|
|
2
|
|
11
|
use Exporter; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
84
|
|
6
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION @ISA @EXPORT_OK); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
210
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
7
|
$VERSION = '0.034'; |
9
|
2
|
|
|
|
|
28
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
|
|
43
|
@EXPORT_OK = qw( |
12
|
|
|
|
|
|
|
set_tty_color |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
} |
15
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
961
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %color_indexes = ( |
19
|
|
|
|
|
|
|
0 => 'P0', #black |
20
|
|
|
|
|
|
|
1 => 'P8', # dark grey |
21
|
|
|
|
|
|
|
2 => 'P1', # dark red |
22
|
|
|
|
|
|
|
3 => 'P9', # red |
23
|
|
|
|
|
|
|
4 => 'P2', # dark green |
24
|
|
|
|
|
|
|
5 => 'PA', # green |
25
|
|
|
|
|
|
|
6 => 'P3', # brown |
26
|
|
|
|
|
|
|
7 => 'PB', # yellow |
27
|
|
|
|
|
|
|
8 => 'P4', # darkblue |
28
|
|
|
|
|
|
|
9 => 'PC', # blue |
29
|
|
|
|
|
|
|
10 => 'P5', # dark magenta |
30
|
|
|
|
|
|
|
11 => 'PD', # magenta |
31
|
|
|
|
|
|
|
12 => 'P6', # dark cyan |
32
|
|
|
|
|
|
|
13 => 'PE', # cyan |
33
|
|
|
|
|
|
|
14 => 'P7', # dark white |
34
|
|
|
|
|
|
|
15 => 'PF', # white |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub set_tty_color { |
39
|
1
|
|
|
1
|
1
|
85
|
my $map = shift; |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
5
|
ref($map) eq 'HASH' or croak("set_tty_color() expects an hashref"); |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
2
|
my %results; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
3
|
for my $index(sort{ $a <=> $b } keys(%{$map})) { |
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
5
|
|
46
|
1
|
50
|
33
|
|
|
8
|
if( ($index < 0) or ($index > 15) ) { |
47
|
0
|
|
|
|
|
0
|
croak("'$index': color index must be between 0 and 15, inclusive\n"); |
48
|
|
|
|
|
|
|
} |
49
|
1
|
50
|
|
|
|
6
|
if($map->{$index} !~ m/^(?:[A-Za-z0-9]{6}$)/) { |
50
|
0
|
|
|
|
|
0
|
croak( |
51
|
|
|
|
|
|
|
"'$map->{$index}' is not a valid hexadecimal color representation\n" |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$results{$index} = sprintf("\e]%s", |
56
|
|
|
|
|
|
|
$color_indexes{$index} |
57
|
1
|
|
|
|
|
8
|
. $map->{$index}, #P0ffffff |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
3
|
return \%results; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |