line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# Curses::UI::Color |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (c) 2003 by Marcus Thiesen. All rights reserved. |
5
|
|
|
|
|
|
|
# This file is part of Curses::UI. Curses::UI is free software. |
6
|
|
|
|
|
|
|
# You can redistribute it and/or modify it under the same terms |
7
|
|
|
|
|
|
|
# as perl itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# e-mail: marcus@cpan.thiesenweb.de |
10
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Curses::UI::Color; |
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
45
|
use Curses; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
24915
|
|
15
|
8
|
|
|
8
|
|
73
|
use Curses::UI::Common; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
1136
|
|
16
|
8
|
|
|
8
|
|
141
|
use strict; |
|
8
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
332
|
|
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
5381
|
use vars qw( |
19
|
|
|
|
|
|
|
@ISA |
20
|
|
|
|
|
|
|
$VERSION |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
|
42
|
); |
|
8
|
|
|
|
|
15
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$VERSION = "0.01"; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
@ISA = qw( |
27
|
|
|
|
|
|
|
Curses::UI::Common |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my %userargs = @_; |
34
|
1
|
|
|
|
|
5
|
keys_to_lowercase(\%userargs); |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
5
|
my %args = ( |
37
|
|
|
|
|
|
|
-default_colors => 1, |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
%userargs, |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
6
|
if ( $args{-default_colors} ) { |
44
|
1
|
|
|
|
|
10
|
use_default_colors(); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
175
|
start_color(); |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
174
|
my $this = bless { %args }, $class; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
8
|
$this->{cmap} = { |
52
|
|
|
|
|
|
|
black => COLOR_BLACK, |
53
|
|
|
|
|
|
|
red => COLOR_RED, |
54
|
|
|
|
|
|
|
green => COLOR_GREEN, |
55
|
|
|
|
|
|
|
yellow => COLOR_YELLOW, |
56
|
|
|
|
|
|
|
blue => COLOR_BLUE, |
57
|
|
|
|
|
|
|
magenta => COLOR_MAGENTA, |
58
|
|
|
|
|
|
|
cyan => COLOR_CYAN, |
59
|
|
|
|
|
|
|
white => COLOR_WHITE, |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
1195
|
$this->{pmap} = {}; |
63
|
1
|
|
|
|
|
4
|
$this->{pcount} = 0; |
64
|
1
|
|
|
|
|
2
|
$this->{ccount} = 7; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
6
|
return $this; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_color_pair { |
70
|
0
|
|
|
0
|
0
|
|
my $this = shift; |
71
|
0
|
|
|
|
|
|
my $fg = shift; |
72
|
0
|
|
|
|
|
|
my $bg = shift; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
return unless defined $fg; |
75
|
0
|
0
|
|
|
|
|
return unless defined $bg; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $fgn = $this->{cmap}->{"$fg"}; |
78
|
0
|
|
|
|
|
|
my $bgn = $this->{cmap}->{"$bg"}; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
$fgn = -1 unless defined $fgn; |
81
|
0
|
0
|
|
|
|
|
$bgn = -1 unless defined $bgn; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ($this->{pmap}->{"$fg.$bg"}) { |
84
|
0
|
|
|
|
|
|
return $this->{pmap}->{"$fg.$bg"}; |
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
$this->{pcount}++; |
87
|
0
|
|
|
|
|
|
init_pair($this->{pcount}, $fgn, $bgn); |
88
|
0
|
|
|
|
|
|
$this->{pmap}->{"$fg.$bg"} = $this->{pcount}; |
89
|
0
|
|
|
|
|
|
return $this->{pcount}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_colors { |
94
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
95
|
0
|
|
|
|
|
|
return keys %{$this->{cmap}}; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub colors { |
99
|
0
|
|
|
0
|
1
|
|
return $Curses::UI::color_support; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub define_color { |
103
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
104
|
0
|
|
|
|
|
|
my $name = shift; |
105
|
0
|
|
|
|
|
|
my ($r, $g, $b) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return unless $r < 1000; |
108
|
0
|
0
|
|
|
|
|
return unless $g < 1000; |
109
|
0
|
0
|
|
|
|
|
return unless $b < 1000; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
return unless $r > 0; |
112
|
0
|
0
|
|
|
|
|
return unless $g > 0; |
113
|
0
|
0
|
|
|
|
|
return unless $b > 0; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
init_color($this->{ccount}, $r, $g, $b); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$this->{cmap}->{$name} = $this->{ccount}; |
118
|
0
|
|
|
|
|
|
$this->{ccount}++; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return 1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=pod |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 NAME |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Curses::UI::Color - Color support module |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 WARNING |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This is a development version. As I do not expect to change |
134
|
|
|
|
|
|
|
the interface during this time it may happen that the color |
135
|
|
|
|
|
|
|
behaviour (e.g. to what extend color is drawn in a window) |
136
|
|
|
|
|
|
|
may change or even the colors themselves. If you want something |
137
|
|
|
|
|
|
|
stable, use -color_support => 0 , but you won't get those fency |
138
|
|
|
|
|
|
|
colors then :-) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 DESCRIPTION |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This module provides all functions related to color support in |
143
|
|
|
|
|
|
|
Curses::UI. The color support was implemented without disturbing |
144
|
|
|
|
|
|
|
old applications, they will look as they used to do. Only if you |
145
|
|
|
|
|
|
|
enable color support explicitly and it is available on your terminal |
146
|
|
|
|
|
|
|
the color functions will have an effect. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SYNOPSIS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $cui = new Curses::UI(-color_support => 1, |
151
|
|
|
|
|
|
|
-clear_on_exit => 0); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $mainw = $cui->add('screen', 'Window'); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$mainw->add('l','Label', -bg => "white", |
156
|
|
|
|
|
|
|
-fg => "blue", |
157
|
|
|
|
|
|
|
-text => "Colored Label"); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 METHODS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=over 4 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * B (-default-colors => BOOLEAN) |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Creates a new Curses::UI::Color object, the option |
168
|
|
|
|
|
|
|
default colors define if the use_default_colors function |
169
|
|
|
|
|
|
|
of Curses is used. See L for that. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * B ( ) |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns all in this object defined colors as an array |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * B ( ) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Is true if color support is enabled. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * B ( NAME, R, G, B ) |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This function defines a new color in the Color object. The |
182
|
|
|
|
|
|
|
RGB values can be between 0 and 1000. Existing colors can |
183
|
|
|
|
|
|
|
be redefined. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 USAGE |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Curses::UI has 7 predefined colors: |
190
|
|
|
|
|
|
|
black |
191
|
|
|
|
|
|
|
red |
192
|
|
|
|
|
|
|
green |
193
|
|
|
|
|
|
|
yellow |
194
|
|
|
|
|
|
|
blue |
195
|
|
|
|
|
|
|
magenta |
196
|
|
|
|
|
|
|
cyan |
197
|
|
|
|
|
|
|
white |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Curses::UI with color support also defines some new options: |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
-fg -bg for general foreground and background color. |
202
|
|
|
|
|
|
|
-tfg -tbg for widget title fg and bg color |
203
|
|
|
|
|
|
|
-bfg -bbg for widget border fg and bg color |
204
|
|
|
|
|
|
|
-sfg -sbg for scrollbar fg and bg color |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Every widget has has a runtime setter: |
207
|
|
|
|
|
|
|
set_color_fg ( COLOR ) |
208
|
|
|
|
|
|
|
set_colof_bg ( COLOR ) |
209
|
|
|
|
|
|
|
set_color_tfg ( COLOR ) |
210
|
|
|
|
|
|
|
set_colof_tbg ( COLOR ) |
211
|
|
|
|
|
|
|
set_color_bfg ( COLOR ) |
212
|
|
|
|
|
|
|
set_colof_bbg ( COLOR ) |
213
|
|
|
|
|
|
|
set_color_sfg ( COLOR ) |
214
|
|
|
|
|
|
|
set_colof_sbg ( COLOR ) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Mostly every widget has a -fg and -bg option to set the foreground |
217
|
|
|
|
|
|
|
and background color using the above color names. Own colors can be |
218
|
|
|
|
|
|
|
defined using the B method. Every widget that |
219
|
|
|
|
|
|
|
supports color by now has also two functions B and |
220
|
|
|
|
|
|
|
B to set or change the color at runtime. |
221
|
|
|
|
|
|
|
Widgets with borders and scrollbars can use -bfg and -bbg to set the |
222
|
|
|
|
|
|
|
foreground and background color of the border or the -sfg and -sbg |
223
|
|
|
|
|
|
|
option to set the colors of the scrollbar. |
224
|
|
|
|
|
|
|
Widgets with titles can set the -tfg and -tbg option to define |
225
|
|
|
|
|
|
|
the title foreground and background color. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Check also the examples/color_editor for seeing what is possible |
228
|
|
|
|
|
|
|
at the moment. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 SEE ALSO |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
L |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Copyright (c) 2003 Marcus Thiesen. All rights reserved. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de) |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This package is free software and is provided "as is" without express |
241
|
|
|
|
|
|
|
or implied warranty. It may be used, redistributed and/or modified |
242
|
|
|
|
|
|
|
under the same terms as perl itself. |
243
|
|
|
|
|
|
|
|