line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UI::Various::PoorTerm::Box; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Author, Copyright and License: see end of file |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
UI::Various::PoorTerm::Box - concrete implementation of L |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# This module should never be used directly! |
12
|
|
|
|
|
|
|
# It is used indirectly via the following: |
13
|
|
|
|
|
|
|
use UI::Various::Box; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 ABSTRACT |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module is the specific minimal fallback implementation of |
18
|
|
|
|
|
|
|
L. It manages and hides everything specific to the last |
19
|
|
|
|
|
|
|
resort UI. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The documentation of this module is only intended for developers of the |
24
|
|
|
|
|
|
|
package itself. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
######################################################################### |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
|
27
|
use v5.14; |
|
2
|
|
|
|
|
6
|
|
31
|
2
|
|
|
2
|
|
11
|
use strictures; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
32
|
2
|
|
|
2
|
|
383
|
no indirect 'fatal'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
33
|
2
|
|
|
2
|
|
127
|
no multidimensional; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
34
|
2
|
|
|
2
|
|
79
|
use warnings 'once'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
2
|
|
12
|
use UI::Various::core; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
24
|
|
39
|
2
|
|
|
2
|
|
13
|
use UI::Various::Box; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
40
|
2
|
|
|
2
|
|
853
|
use UI::Various::PoorTerm::container; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2021
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
require Exporter; |
43
|
|
|
|
|
|
|
our @ISA = qw(UI::Various::Box UI::Various::PoorTerm::container); |
44
|
|
|
|
|
|
|
our @EXPORT_OK = qw(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
######################################################################### |
47
|
|
|
|
|
|
|
######################################################################### |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
######################################################################### |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 B<_show> - print UI element |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$ui_element->_show($prefix); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 example: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$_->_show('(1) '); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head3 parameters: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$prefix text in front of first line |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head3 description: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Show the complete box by printing a separator (blank line unless the border |
70
|
|
|
|
|
|
|
should be visible) and its indented content. If the box is not indented, |
71
|
|
|
|
|
|
|
its active elements are numbered to allow later interaction with them. |
72
|
|
|
|
|
|
|
I
|
73
|
|
|
|
|
|
|
action of UI element>> or a I::Various::PoorTerm container element!> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _show($$) |
80
|
|
|
|
|
|
|
{ |
81
|
39
|
|
|
39
|
|
12470
|
my ($self, $prefix) = @_; |
82
|
39
|
100
|
|
|
|
148
|
defined $prefix or $prefix = ''; |
83
|
39
|
|
|
|
|
203
|
my $blank = ' ' x length($prefix); |
84
|
39
|
|
|
|
|
67
|
local $_; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# The number of '_show' parents' calls is the indention level: |
87
|
39
|
|
|
|
|
70
|
my $level = 0; |
88
|
39
|
|
|
|
|
154
|
$level++ while (caller($level + 1))[3] =~ m/::_show$/; |
89
|
39
|
100
|
|
|
|
1340
|
my $indent = $level <= 1 ? '' : ' '; |
90
|
39
|
100
|
|
|
|
176
|
my $border = $self->border ? '----------' : ''; |
91
|
|
|
|
|
|
|
|
92
|
39
|
100
|
|
|
|
975
|
$prefix ne '' and print $indent, $prefix, $border, "\n"; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# 1st gather active children and get width of prefix: |
95
|
39
|
|
|
|
|
194
|
$self->{_active} = []; |
96
|
39
|
|
|
|
|
237
|
while ($_ = $self->child) |
97
|
|
|
|
|
|
|
{ |
98
|
86
|
100
|
|
|
|
370
|
$_->can('_process') and push @{$self->{_active}}, $_; |
|
61
|
|
|
|
|
186
|
|
99
|
|
|
|
|
|
|
} |
100
|
39
|
|
|
|
|
76
|
my $active = @{$self->{_active}}; |
|
39
|
|
|
|
|
80
|
|
101
|
39
|
|
|
|
|
71
|
$_ = length($active); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# print children: |
104
|
39
|
|
|
|
|
117
|
my $pre_active = '<%' . $_ . 'd> '; |
105
|
39
|
|
|
|
|
95
|
my $pre_passive = ' ' x ($_ + 3); |
106
|
39
|
|
|
|
|
61
|
my $i = 1; |
107
|
39
|
|
|
|
|
126
|
foreach my $row (0..($self->rows - 1)) |
108
|
|
|
|
|
|
|
{ |
109
|
58
|
|
|
|
|
214
|
foreach my $column (0..($self->columns - 1)) |
110
|
|
|
|
|
|
|
{ |
111
|
102
|
|
|
|
|
338
|
$_ = $self->field($row, $column); |
112
|
102
|
100
|
|
|
|
217
|
next unless defined $_; |
113
|
86
|
|
|
|
|
134
|
my $pre_child = $indent; |
114
|
86
|
100
|
|
|
|
302
|
if ($prefix =~ m/[^ ]/) |
|
|
100
|
|
|
|
|
|
115
|
|
|
|
|
|
|
{ |
116
|
32
|
100
|
100
|
|
|
158
|
if ($active == 1 and $_->can('_process')) |
117
|
9
|
|
|
|
|
30
|
{ $pre_child .= '<*> '; } |
118
|
|
|
|
|
|
|
else |
119
|
23
|
|
|
|
|
45
|
{ $pre_child .= $blank; } |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
elsif ($prefix eq '') |
122
|
|
|
|
|
|
|
{ |
123
|
42
|
100
|
|
|
|
243
|
$pre_child .= $_->can('_process') |
124
|
|
|
|
|
|
|
? sprintf($pre_active, $i++) : $pre_passive; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
else |
127
|
12
|
|
|
|
|
20
|
{ $pre_child .= $blank; } |
128
|
86
|
|
|
|
|
319
|
$_->_show($pre_child); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# finish as child or master of selection: |
133
|
39
|
100
|
|
|
|
236
|
if ($prefix ne '') |
134
|
|
|
|
|
|
|
{ |
135
|
22
|
|
|
|
|
334
|
print $indent, $blank, $border, "\n"; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else |
138
|
|
|
|
|
|
|
{ |
139
|
|
|
|
|
|
|
# print standard selection strings: |
140
|
17
|
|
|
|
|
153
|
print $self->_wrap(sprintf($pre_active, 0), msg('leave_box')), "\n\n"; |
141
|
17
|
|
|
|
|
121
|
print $self->_wrap('----- ', |
142
|
|
|
|
|
|
|
msg('enter_number_to_choose_next_step')), ': '; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
######################################################################### |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 B<_process> - handle action of UI element |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$ui_element->_process; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head3 description: |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Handle the action of the UI element. For a C's box this means: If |
155
|
|
|
|
|
|
|
the box has no active element, just return. If it has exactly one active |
156
|
|
|
|
|
|
|
element, the active element is processed directly. Otherwise the method |
157
|
|
|
|
|
|
|
iterates through a loop of printing the box's elements and allowing to |
158
|
|
|
|
|
|
|
select one of the active ones for processing until the box is exited. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _process($) |
165
|
|
|
|
|
|
|
{ |
166
|
5
|
|
|
5
|
|
6604
|
debug(3, __PACKAGE__, '::_process'); |
167
|
5
|
|
|
|
|
20
|
my ($self) = @_; |
168
|
|
|
|
|
|
|
|
169
|
5
|
|
|
|
|
11
|
my $active = @{$self->{_active}}; |
|
5
|
|
|
|
|
17
|
|
170
|
5
|
100
|
|
|
|
32
|
$active == 1 and $self->{_active}->[0]->_process; |
171
|
5
|
100
|
|
|
|
119
|
$active <= 1 and return 0; |
172
|
|
|
|
|
|
|
|
173
|
3
|
|
|
|
|
8
|
while (1) |
174
|
|
|
|
|
|
|
{ |
175
|
11
|
|
|
|
|
124
|
$self->_show; |
176
|
11
|
|
|
|
|
91
|
local $_ = ; |
177
|
11
|
|
|
|
|
101
|
print $_; |
178
|
11
|
|
|
|
|
180
|
s/\r?\n$//; |
179
|
11
|
100
|
|
|
|
62
|
return $_ if m/^0$/; |
180
|
8
|
100
|
100
|
|
|
117
|
unless ($_ =~ m/^\d+$/ and $_ <= @{$self->{_active}}) |
|
7
|
|
|
|
|
116
|
|
181
|
2
|
|
|
|
|
15
|
{ error('invalid_selection'); next; } |
|
2
|
|
|
|
|
5
|
|
182
|
6
|
|
|
|
|
65
|
$self->{_active}->[$_-1]->_process; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
######################################################################### |
189
|
|
|
|
|
|
|
######################################################################### |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 SEE ALSO |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L, L |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 LICENSE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Copyright (C) Thomas Dorner. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
200
|
|
|
|
|
|
|
under the same terms as Perl itself. See LICENSE file for more details. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 AUTHOR |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Thomas Dorner Edorner (at) cpan (dot) orgE |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |