blib/lib/Curses/UI/Color.pm

filter: Statementstmt 46.6% 28 / 60 Branchbran 4.1% 1 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 80.0% 4 / 5 totaltotal 38.7% 38 / 98 CC 13 SCAR 34.4
CC
13
Cov
35%
define_color
56.0
get_color_pair
42.0
new
2.0
CRAP 31.2
« blib/lib/Curses/UI/Searchable.pm ↑ Summary lib/Curses/UI.pm »
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 ▶use Curses;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Curses::UI::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
19 @ISA
20 $VERSION
21  
22 8 );
23  
24 8 $VERSION = "0.01";
25  
26 8 @ISA = qw(
27 Curses::UI::Common
28 );
29  
30 1 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
31 1 my $class = shift;
32  
33 1 my %userargs = @_;
34 1 keys_to_lowercase(\%userargs);
35  
36 1 my %args = (
37 -default_colors => 1,
38
39 %userargs,
40
41 );
42  
43 1 ▶ if ( $args{-default_colors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-default_colors"}) 1 0 1
44 1 use_default_colors();
45 }
46
47 1 start_color();
48  
49 1 my $this = bless { %args }, $class;
50  
51 $this->{cmap} = {
52 1 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 $this->{pmap} = {};
63 1 $this->{pcount} = 0;
64 1 $this->{ccount} = 7;
65  
66 1 return $this;
67 }
68  
69 0 ▶sub get_color_pair {
Subroutine get_color_pair: not called CC=6 SCAR=37.4
Pod undocumented
70 0 my $this = shift;
71 0 my $fg = shift;
72 0 my $bg = shift;
73  
74 0 ▶ return unless defined $fg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fg 0 0 0
75 0 ▶ return unless defined $bg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bg 0 0 0
76  
77 0 my $fgn = $this->{cmap}->{"$fg"};
78 0 my $bgn = $this->{cmap}->{"$bg"};
79
80 0 ▶ $fgn = -1 unless defined $fgn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fgn 0 0 0
81 0 ▶ $bgn = -1 unless defined $bgn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bgn 0 0 0
82  
83 0 ▶ if ($this->{pmap}->{"$fg.$bg"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'pmap'}{"$fg.$bg"}) { } 0 0 0
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 0 ▶sub get_colors {
Subroutine get_colors: not called CC=1 SCAR=6.9
Pod documented
94 0 my $this = shift;
95 0 return keys %{$this->{cmap}};
96 }
97  
98 0 ▶sub colors {
Subroutine colors: not called CC=1 SCAR=6.9
Pod documented
99 0 return $Curses::UI::color_support;
100 }
101  
102 0 ▶sub define_color {
Subroutine define_color: not called CC=7 SCAR=40.3
Pod documented
103 0 my $this = shift;
104 0 my $name = shift;
105 0 my ($r, $g, $b) = @_;
106  
107 0 ▶ return unless $r < 1000;
Branch: 1 branch
BranchTrueFalseTotal
unless $r < 1000 0 0 0
108 0 ▶ return unless $g < 1000;
Branch: 1 branch
BranchTrueFalseTotal
unless $g < 1000 0 0 0
109 0 ▶ return unless $b < 1000;
Branch: 1 branch
BranchTrueFalseTotal
unless $b < 1000 0 0 0
110
111 0 ▶ return unless $r > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $r > 0 0 0 0
112 0 ▶ return unless $g > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $g > 0 0 0 0
113 0 ▶ return unless $b > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $b > 0 0 0 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 8 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<new> (-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<Curses> for that.
170  
171 =item * B<get_colors> ( )
172  
173 Returns all in this object defined colors as an array
174  
175 =item * B<colors> ( )
176  
177 Is true if color support is enabled.
178  
179 =item * B<define_color> ( 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<define_color> method. Every widget that
219 supports color by now has also two functions B<set_color_fg> and
220 B<set_color_bg> 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<Curses::UI>
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  
« blib/lib/Curses/UI/Searchable.pm ↑ Summary lib/Curses/UI.pm »