lib/TUI/Menus/StatusLine.pm

filter: Statementstmt 26.8% 57 / 212 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 50.0% 15 / 30 Podpod 90.9% 10 / 11 totaltotal 22.6% 82 / 362 CC 49 SCAR 43.5
CC
49
Cov
18%
__ANON__
185.5
handleEvent
157.9
__ANON__
90.0
CRAP 77.8
« lib/TUI/Views/View/Write.pm ↑ Summary lib/TUI/StdDlg/DirListBox.pm »
1 package TUI::Menus::StatusLine;
2 # ABSTRACT: Message line for the bottom of the application screen
3
4 40 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 40 our $VERSION = '2.000002';
9 40 $VERSION =~ tr/_//d;
10 40 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 40 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 40 our @EXPORT = qw(
14 TStatusLine
15 new_TStatusLine
16 );
17
18 40 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 40 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 Maybe
21 is_Object
22 :types
23 40 );
24
25 40 ▶use TUI::Menus::Const qw( cpStatusLine );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 40 ▶use TUI::Drivers::Const qw( :evXXXX );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use TUI::Drivers::Util qw( cstrlen );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 40 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 cmCommandSetChanged
31 :gfXXXX
32 hcNoContext
33 ofPreProcess
34 40 );
35 40 ▶use TUI::Views::Palette;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 40 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
37
38 sub TStatusLine() { __PACKAGE__ }
39 sub name() { 'TStatusLine' }
40 0 ▶sub new_TStatusLine { __PACKAGE__->from(@_) }
Subroutine new_TStatusLine: not called CC=1 SCAR=6.9
Pod documented
41
42 40 extends TView;
43
44 # declare global variables
45 40 our $hintSeparator = "\xB3 ";
46
47 # protected attributes
48 40 has items => ( is => 'ro' );
49 0 ▶has defs => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
50
51 # predeclare private methods
52 my (
53 40 $drawSelect,
54 $findItems,
55 $itemMouseIsIn,
56 );
57
58 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
59 0 state $sig = signature(
60 method => 1,
61 named => [
62 bounds => Object,
63 defs => Maybe[Object], { alias => 'aDefs' },
64 ],
65 caller_level => +1,
66 );
67 0 my ( $class, $args ) = $sig->( @_ );
68 0 return { %$args };
69 }
70
71 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
72 0 my ( $self, $args ) = @_;
73 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
74 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
75 0 $self->{options} |= ofPreProcess;
76 0 $self->{eventMask} |= evBroadcast;
77 0 $self->{growMode} = gfGrowLoY | gfGrowHiX | gfGrowHiY;
78 0 $self->$findItems();
79 0 return;
80 } #/ sub new
81
82 0 ▶sub from { # $obj ($bounds, $aDefs|undef)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
83 0 state $sig = signature(
84 method => 1,
85 pos => [ Object, Maybe[Object] ],
86 );
87 0 my ( $class, @args ) = $sig->( @_ );
88 0 return $class->new( bounds => $args[0], defs => $args[1] );
89 }
90
91 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=4 SCAR=30.0
Pod documented
92 0 my ( $self, $in_global_destruction ) = @_;
93 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
94 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
95 0 ▶ while ( $self->{defs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"defs"}) 0 0 0
96 0 my $T = $self->{defs};
97 0 $self->{defs} = $self->{defs}{next};
98 0 $self->disposeItems( $T->{items} );
99 0 undef $T;
100 }
101 0 return;
102 }
103
104 0 ▶sub disposeItems { # void ($item|undef)
Subroutine disposeItems: not called CC=3 SCAR=24.8
Pod documented
105 0 state $sig = signature(
106 method => Object,
107 pos => [Maybe[Object]],
108 );
109 0 my ( $self, $item ) = $sig->( @_ );
110 0 ▶ while ( $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item) 0 0 0
111 0 alias: for my $T ( $item ) {
112 0 $item = $item->next;
113 0 undef $T;
114 } #/ alias
115 }
116 0 return;
117 }
118
119 0 ▶sub draw { # void ()
Subroutine draw: not called CC=1 SCAR=6.9
Pod documented
120 0 state $sig = signature(
121 method => Object,
122 pos => [],
123 );
124 0 my ( $self ) = $sig->( @_ );
125 0 $self->$drawSelect( undef );
126 0 return;
127 }
128
129 0 ▶sub getPalette { # $palette ()
Subroutine getPalette: not called CC=1 SCAR=6.9
Pod documented
130 0 state $sig = signature(
131 method => Object,
132 pos => [],
133 );
134 0 my ( $self ) = $sig->( @_ );
135 0 state $palette = TPalette->new(
136 data => cpStatusLine,
137 size => length( cpStatusLine ),
138 );
139 0 return $palette->clone();
140 }
141
142 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=13 SCAR=50.6
Pod documented
143 40 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
144 0 state $sig = signature(
145 method => Object,
146 pos => [Object],
147 );
148 0 my ( $self, $event ) = $sig->( @_ );
149 0 $self->SUPER::handleEvent( $event );
150
151 0 SWITCH: for ( $event->{what} ) {
152 0 ▶ $_ == evMouseDown and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ == 1 and do { my $T; do { my $mouse = $self->makeLocal($event->{"mouse"}{"where"}); if ($T != $self->$itemMouseIsIn($mouse)) { $self->$drawSelect($T = $self->$itemMouseIsIn($mouse)); } } while $self->mouseEvent($event, 4); if ($T and "TUI::Views::View"->commandEnabled($T->{"command"})) { $event->{"what"} = 256; $event->{"message"}{"command"} = $T->{"command"}; $event->{"message"}{"infoPtr"} = undef; $self->putEvent($event); } ; $self->clearEvent($event); $self->drawView; last } 0 0 0
153 0 my $T;
154 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->mouseEvent($event, 4) and do { do { my $mouse = $self->makeLocal($event->{"mouse"}{"where"}); if ($T != $self->$itemMouseIsIn($mouse)) { $self->$drawSelect($T = $self->$itemMouseIsIn($mouse)); } } } 0 0 0
155 0 my $mouse = $self->makeLocal( $event->{mouse}{where} );
156 0 ▶ if ( $T != $self->$itemMouseIsIn( $mouse ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T != $self->$itemMouseIsIn($mouse)) 0 0 0
157 0 $self->$drawSelect( $T = $self->$itemMouseIsIn( $mouse ) );
158 }
159 } while ( $self->mouseEvent( $event, evMouseMove ) );
160
161 0 ▶ if ( $T && TView->commandEnabled( $T->{command} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T and "TUI::Views::View"->commandEnabled($T->{"command"})) 0 0 0
Condition0%0/3
$T and "TUI::Views::View"->commandEnabled($T->{"command"})
!ll&&!rl&&r
000
MC/DC0%0/2
$T and "TUI::Views::View"->commandEnabled($T->{"command"})
$T "TUI::Views::View"->commandEnabled($T->{"command"})
Truth table0%0/3
A and B
A= $TB= "TUI::Views::View"->commandEnabled($T->{"command"})
ABresult
0X0
100
111
162 0 $event->{what} = evCommand;
163 0 $event->{message}{command} = $T->{command};
164 0 $event->{message}{infoPtr} = undef;
165 0 $self->putEvent( $event );
166 }
167 0 $self->clearEvent( $event );
168 0 $self->drawView();
169 0 last;
170 };
171 0 ▶ $_ == evKeyDown and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ == 16 and do { my $T = $self->{"items"}; while ($T) { if ($event->{"keyDown"}{"keyCode"} == $T->{"keyCode"} and "TUI::Views::View"->commandEnabled($T->{"command"})) { $event->{"what"} = 256; $event->{"message"}{"command"} = $T->{"command"}; $event->{"message"}{"infoPtr"} = undef; return; } ; $T = $T->{"next"}; } ; last } 0 0 0
172 0 my $T = $self->{items};
173 0 ▶ while ( $T ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T) 0 0 0
174 0 ▶ if ( $event->{keyDown}{keyCode} == $T->{keyCode}
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"keyDown"}{"keyCode"} == $T->{"keyCode"} and "TUI::Views::View"->commandEnabled($T->{"command"})) 0 0 0
Condition0%0/3
$event->{"keyDown"}{"keyCode"} == $T->{"keyCode"} and "TUI::Views::View"->commandEnabled($T->{"command"})
!ll&&!rl&&r
000
MC/DC0%0/2
$event->{"keyDown"}{"keyCode"} == $T->{"keyCode"} and "TUI::Views::View"->commandEnabled($T->{"command"})
$event->{"keyDown"}{"keyCode"} == $T->{"keyCode"} "TUI::Views::View"->commandEnabled($T->{"command"})
Truth table0%0/3
A and B
A= $event->{"keyDown"}{"keyCode"} == $T->{"keyCode"}B= "TUI::Views::View"->commandEnabled($T->{"command"})
ABresult
0X0
100
111
175 && TView->commandEnabled( $T->{command} ) )
176 {
177 0 $event->{what} = evCommand;
178 0 $event->{message}{command} = $T->{command};
179 0 $event->{message}{infoPtr} = undef;
180 0 return;
181 }
182 0 $T = $T->{next};
183 } #/ while ( $T )
184 0 last;
185 };
186 0 ▶ $_ == evBroadcast and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ == 512 and do { if ($event->{"message"}{"command"} == 52) { $self->drawView; } ; last } 0 0 0
187 0 ▶ if ( $event->{message}{command} == cmCommandSetChanged
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"message"}{"command"} == 52) 0 0 0
188 ) {
189 0 $self->drawView();
190 }
191 0 last;
192 };
193 }
194 0 return;
195 } #/ sub handleEvent
196
197 0 ▶sub hint { # $str ($aHelpCtx)
Subroutine hint: not called CC=1 SCAR=6.9
Pod documented
198 0 state $sig = signature(
199 method => Object,
200 pos => [PositiveOrZeroInt],
201 );
202 0 my ( $self, $aHelpCtx ) = $sig->( @_ );
203 0 return '';
204 }
205
206 0 ▶sub update { # void ()
Subroutine update: not called CC=3 SCAR=24.8
Pod documented
207 0 state $sig = signature(
208 method => Object,
209 pos => [],
210 );
211 0 my ( $self ) = $sig->( @_ );
212 0 my $p = $self->TopView();
213 0 ▶ my $h = $p ? $p->getHelpCtx() : hcNoContext;
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 0 0 0
214 0 ▶ if ( $self->{helpCtx} != $h ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"helpCtx"} != $h) 0 0 0
215 0 $self->{helpCtx} = $h;
216 0 $self->$findItems();
217 0 $self->drawView();
218 }
219 0 return;
220 } #/ sub update
221
222 0 ▶$drawSelect = sub { # void ($selected|undef)
Subroutine __ANON__: not called CC=14 SCAR=52.2
223 0 my ( $self, $selected ) = @_;
224 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
225 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
226 0 ▶ assert ( !defined $selected or is_Object $selected );
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $selected or &is_Object($selected) 0 0 0
Condition0%0/3
not defined $selected or &is_Object($selected)
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $selected or &is_Object($selected)
not defined $selected &is_Object($selected)
Truth table0%0/3
not(A) or B
A= not defined $selectedB= &is_Object($selected)
ABresult
1X1
011
000
227 0 my $b = TDrawBuffer->new();
228
229 0 my $cNormal = $self->getColor( 0x0301 );
230 0 my $cSelect = $self->getColor( 0x0604 );
231 0 my $cNormDisabled = $self->getColor( 0x0202 );
232 0 my $cSelDisabled = $self->getColor( 0x0505 );
233 0 $b->moveChar( 0, ' ', $cNormal, $self->{size}{x} );
234 0 my $T = $self->{items};
235 0 my $i = 0;
236
237 0 ▶ while ( $T ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T) 0 0 0
238 0 ▶ if ( $T->{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T->{"text"}) 0 0 0
239 0 my $l = cstrlen( $T->{text} );
240 0 ▶ if ( $i + $l < $self->{size}{x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + $l < $self->{"size"}{"x"}) 0 0 0
241 40 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
242 0 my $color;
243 0 ▶ if ( TView->commandEnabled( $T->{command} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('TUI::Views::View'->commandEnabled($T->{'command'})) { } 0 0 0
244 0 ▶ $color = ( $T == $selected )
Branch: 1 branch
BranchTrueFalseTotal
$T == $selected ? : 0 0 0
245 ? $cSelect
246 : $cNormal;
247 }
248 else {
249 0 ▶ $color = ( $T == $selected )
Branch: 1 branch
BranchTrueFalseTotal
$T == $selected ? : 0 0 0
250 ? $cSelDisabled
251 : $cNormDisabled;
252 }
253 0 $b->moveChar( $i, ' ', $color, 1 );
254 0 $b->moveCStr( $i + 1, $T->{text}, $color );
255 0 $b->moveChar( $i + $l + 1, ' ', $color, 1 );
256 } #/ if ( $i + $l < $self->...)
257 0 $i += $l + 2;
258 } #/ if ( $T->{text} )
259 0 $T = $T->{next};
260 } #/ while ( $T )
261 0 ▶ if ( $i < $self->{size}{x} - 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"size"}{"x"} - 2) 0 0 0
262 0 my $hintBuf = $self->hint( $self->{helpCtx} );
263 0 ▶ if ( $hintBuf ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hintBuf ne "") 0 0 0
264 0 $b->moveStr( $i, $hintSeparator, $cNormal );
265 0 $i += 2;
266 0 ▶ if ( length( $hintBuf ) + $i > $self->{size}{x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($hintBuf) + $i > $self->{"size"}{"x"}) 0 0 0
267 0 $hintBuf = substr( $hintBuf, 0, $self->{size}{x} - $i );
268 }
269 0 $b->moveStr( $i, $hintBuf, $cNormal );
270 0 $i += length( $hintBuf );
271 }
272 } #/ if ( $i < $self->{size...})
273 0 $self->writeLine( 0, 0, $self->{size}{x}, 1, $b );
274 0 return;
275 40 }; #/ sub drawSelect
276
277 0 ▶$findItems = sub { # void ()
Subroutine __ANON__: not called CC=7 SCAR=40.3
278 0 my ( $self ) = @_;
279 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
280 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
281 0 my $p = $self->{defs};
282 0 ▶ while ( $p
Branch: 1 branch
BranchTrueFalseTotal
if ($p and $self->{"helpCtx"} < $p->{"min"} || $self->{"helpCtx"} > $p->{"max"}) 0 0 0
Condition0%0/6
$p and $self->{"helpCtx"} < $p->{"min"} || $self->{"helpCtx"} > $p->{"max"}
!ll&&!rl&&r
000
$self->{"helpCtx"} < $p->{"min"} or $self->{"helpCtx"} > $p->{"max"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$p and $self->{"helpCtx"} < $p->{"min"} || $self->{"helpCtx"} > $p->{"max"}
$p $self->{"helpCtx"} < $p->{"min"} $self->{"helpCtx"} > $p->{"max"}
Truth table0%0/4
A and B or C
A= $pB= $self->{"helpCtx"} < $p->{"min"}C= $self->{"helpCtx"} > $p->{"max"}
ABCresult
0XX0
1000
11X1
1011
283 && ( $self->{helpCtx} < $p->{min} || $self->{helpCtx} > $p->{max} )
284 ) {
285 0 $p = $p->{next};
286 }
287 0 ▶ $self->{items} = $p ? $p->{items} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 0 0 0
288 0 return;
289 40 };
290
291 0 ▶$itemMouseIsIn = sub { # $statusItem|undef ($mouse)
Subroutine __ANON__: not called CC=9 SCAR=45.0
292 0 my ( $self, $mouse ) = @_;
293 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
294 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
295 0 ▶ assert ( is_HashLike $mouse );
Branch: 1 branch
BranchTrueFalseTotal
unless $mouse->is_HashLike 0 0 0
296 return undef
297 0 ▶ if $mouse->{y} != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $mouse->{"y"} != 0 0 0 0
298
299 0 my $i = 0;
300 0 my $T = $self->{items};
301
302 0 ▶ while ( $T ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T) 0 0 0
303 0 ▶ if ( $T->{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T->{"text"}) 0 0 0
304 0 my $k = $i + cstrlen( $T->{text} ) + 2;
305 return $T
306 0 ▶ if $mouse->{x} >= $i && $mouse->{x} < $k;
Branch: 1 branch
BranchTrueFalseTotal
if $mouse->{"x"} >= $i and $mouse->{"x"} < $k 0 0 0
Condition0%0/3
$mouse->{"x"} >= $i and $mouse->{"x"} < $k
!ll&&!rl&&r
000
MC/DC0%0/2
$mouse->{"x"} >= $i and $mouse->{"x"} < $k
$mouse->{"x"} >= $i $mouse->{"x"} < $k
Truth table0%0/3
A and B
A= $mouse->{"x"} >= $iB= $mouse->{"x"} < $k
ABresult
0X0
100
111
307 0 $i = $k;
308 }
309 0 $T = $T->{next};
310 }
311 0 return undef;
312 40 }; #/ sub itemMouseIsIn
313
314 40 1
315
316 __END__
« lib/TUI/Views/View/Write.pm ↑ Summary lib/TUI/StdDlg/DirListBox.pm »