| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
|
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2009,2010 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Convert::Color::XTerm; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1452
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
78
|
|
|
9
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
71
|
|
|
10
|
2
|
|
|
2
|
|
22
|
use base qw( Convert::Color::RGB8 ); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
2112
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->register_color_space( 'xterm' ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
83954
|
use Carp; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
2288
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
C<Convert::Color::XTerm> - indexed colors used by XTerm |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Directly: |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Convert::Color::XTerm; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $red = Convert::Color::XTerm->new( 1 ); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Via L<Convert::Color>: |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Convert::Color; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $cyan = Convert::Color->new( 'xterm:14' ); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This subclass of L<Convert::Color::RGB8> provides lookup of the colors that |
|
39
|
|
|
|
|
|
|
F<xterm> uses by default. Note that the module is not intelligent enough to |
|
40
|
|
|
|
|
|
|
actually parse the XTerm configuration on a machine, nor to query a running |
|
41
|
|
|
|
|
|
|
terminal for its actual colors. It simply implements the colors that are |
|
42
|
|
|
|
|
|
|
present as defaults in the XTerm source code. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
It implements the complete 256-color model in XTerm. This range consists of: |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0-7: The basic VGA colors, dark intensity. 7 is a "dark" white, i.e. a light |
|
51
|
|
|
|
|
|
|
grey. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item * |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
8-15: The basic VGA colors, light intensity. 8 represents a "light" black, |
|
56
|
|
|
|
|
|
|
i.e. a dark grey. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item * |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
16-231: A 6x6x6 RGB color cube. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
232-255: 24 greyscale ramp. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my @color; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _init_colors |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
|
|
|
|
|
|
# The first 16 colors are dark and light versions of the basic 8 VGA colors. |
|
75
|
|
|
|
|
|
|
# XTerm itself pulls these from the X11 database, except for light blue. |
|
76
|
|
|
|
|
|
|
# These color names from xterm's charproc.c |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
|
|
1
|
|
3
|
my @colnames; |
|
79
|
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
1
|
if( eval { require Convert::Color::X11; Convert::Color::X11->colors } ) { |
|
|
1
|
|
|
|
|
1087
|
|
|
|
1
|
|
|
|
|
935
|
|
|
81
|
0
|
|
|
|
|
0
|
@colnames = (qw( |
|
82
|
|
|
|
|
|
|
x11:black x11:red3 x11:green3 x11:yellow3 |
|
83
|
|
|
|
|
|
|
x11:blue2 x11:magenta3 x11:cyan3 x11:gray90 |
|
84
|
|
|
|
|
|
|
x11:gray50 x11:red x11:green x11:yellow |
|
85
|
|
|
|
|
|
|
rgb8:5C5CFF x11:magenta x11:cyan x11:white |
|
86
|
|
|
|
|
|
|
)); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
else { |
|
89
|
1
|
|
|
|
|
79
|
@colnames = (qw( |
|
90
|
|
|
|
|
|
|
rgb8:000000 rgb8:cd0000 rgb8:00cd00 rgb8:cdcd00 |
|
91
|
|
|
|
|
|
|
rgb8:0000ee rgb8:cd00cd rgb8:00cdcd rgb8:e5e5e5 |
|
92
|
|
|
|
|
|
|
rgb8:7f7f7f rgb8:ff0000 rgb8:00ff00 rgb8:ffff00 |
|
93
|
|
|
|
|
|
|
rgb8:5c5cff rgb8:ff00ff rgb8:00ffff rgb8:ffffff |
|
94
|
|
|
|
|
|
|
)); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
5
|
foreach my $index ( 0 .. $#colnames ) |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
16
|
|
|
|
|
59
|
my $c_tmp = Convert::Color->new( $colnames[$index] ); |
|
100
|
16
|
|
|
|
|
14734
|
$color[$index] = __PACKAGE__->SUPER::new( $c_tmp->as_rgb8->rgb8 ); |
|
101
|
16
|
|
|
|
|
660
|
$color[$index]->[3] = $index; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# These descriptions and formulae from xterm's 256colres.pl |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Next is a 6x6x6 color cube, with an attempt at a gamma correction |
|
107
|
1
|
|
|
|
|
13
|
foreach my $red ( 0 .. 5 ) { |
|
108
|
6
|
|
|
|
|
9
|
foreach my $green ( 0 .. 5 ) { |
|
109
|
36
|
|
|
|
|
54
|
foreach my $blue ( 0 .. 5 ) { |
|
110
|
216
|
|
|
|
|
311
|
my $index = 16 + ($red*36) + ($green*6) + $blue; |
|
111
|
|
|
|
|
|
|
|
|
112
|
648
|
100
|
|
|
|
1707
|
$color[$index] = __PACKAGE__->SUPER::new( |
|
113
|
216
|
|
|
|
|
267
|
map { $_ ? $_*40 + 55 : 0 } ( $red, $green, $blue ) |
|
114
|
|
|
|
|
|
|
); |
|
115
|
216
|
|
|
|
|
3914
|
$color[$index]->[3] = $index; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Finally a 24-level greyscale ramp |
|
121
|
1
|
|
|
|
|
5
|
foreach my $grey ( 0 .. 23 ) { |
|
122
|
24
|
|
|
|
|
34
|
my $index = 232 + $grey; |
|
123
|
24
|
|
|
|
|
29
|
my $whiteness = $grey*10 + 8; |
|
124
|
|
|
|
|
|
|
|
|
125
|
24
|
|
|
|
|
66
|
$color[$index] = __PACKAGE__->SUPER::new( $whiteness, $whiteness, $whiteness ); |
|
126
|
24
|
|
|
|
|
376
|
$color[$index]->[3] = $index; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__PACKAGE__->register_palette( |
|
131
|
|
|
|
|
|
|
enumerate_once => sub { |
|
132
|
|
|
|
|
|
|
@color or _init_colors; |
|
133
|
|
|
|
|
|
|
@color |
|
134
|
|
|
|
|
|
|
}, |
|
135
|
|
|
|
|
|
|
); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 $color = Convert::Color::XTerm->new( $index ) |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns a new object to represent the color at that index. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub new |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
2
|
|
|
2
|
1
|
14
|
my $class = shift; |
|
150
|
|
|
|
|
|
|
|
|
151
|
2
|
50
|
|
|
|
9
|
if( @_ == 1 ) { |
|
152
|
2
|
|
|
|
|
4
|
my $index = $_[0]; |
|
153
|
|
|
|
|
|
|
|
|
154
|
2
|
100
|
|
|
|
8
|
@color or _init_colors; |
|
155
|
|
|
|
|
|
|
|
|
156
|
2
|
50
|
33
|
|
|
52
|
$index >= 0 and $index < 256 or |
|
157
|
|
|
|
|
|
|
croak "No such XTerm color at index '$index'"; |
|
158
|
|
|
|
|
|
|
|
|
159
|
2
|
|
|
|
|
10
|
return $color[$index]; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
else { |
|
162
|
0
|
|
|
|
|
0
|
croak "usage: Convert::Color::XTerm->new( INDEX )"; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 METHODS |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 $index = $color->index |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The index of the XTerm color. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub index |
|
177
|
|
|
|
|
|
|
{ |
|
178
|
3
|
|
|
3
|
1
|
18177
|
my $self = shift; |
|
179
|
3
|
|
|
|
|
18
|
return $self->[3]; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# Keep perl happy; keep Britain tidy |
|
183
|
|
|
|
|
|
|
1; |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
__END__ |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=over 4 |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L<Convert::Color> - color space conversions |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=back |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Paul Evans <leonerd@leonerd.org.uk> |