line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UI::Various::PoorTerm::Dialog; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Author, Copyright and License: see end of file |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
UI::Various::PoorTerm::Dialog - 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::Dialog; |
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
|
|
18
|
use v5.14; |
|
2
|
|
|
|
|
6
|
|
31
|
2
|
|
|
2
|
|
10
|
use strictures; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
9
|
|
32
|
2
|
|
|
2
|
|
300
|
no indirect 'fatal'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
33
|
2
|
|
|
2
|
|
108
|
no multidimensional; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
34
|
2
|
|
|
2
|
|
79
|
use warnings 'once'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
101
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.24'; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
2
|
|
11
|
use UI::Various::core; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
10
|
|
39
|
2
|
|
|
2
|
|
10
|
use UI::Various::Dialog; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
55
|
|
40
|
2
|
|
|
2
|
|
347
|
use UI::Various::PoorTerm::container; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1527
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
require Exporter; |
43
|
|
|
|
|
|
|
our @ISA = qw(UI::Various::Dialog 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; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 description: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Show the complete dialogue by printing its title and all its elements. Active |
62
|
|
|
|
|
|
|
elements (basically everything not just simple C>) |
63
|
|
|
|
|
|
|
are numbered to allow later interaction with them. I
|
64
|
|
|
|
|
|
|
be called from C>!> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _show($) |
71
|
|
|
|
|
|
|
{ |
72
|
16
|
|
|
16
|
|
3599
|
debug(3, __PACKAGE__, '::_show'); |
73
|
16
|
|
|
|
|
24
|
my ($self) = @_; |
74
|
16
|
|
|
|
|
21
|
local $_; |
75
|
|
|
|
|
|
|
|
76
|
16
|
|
|
|
|
35
|
print $self->_wrap('========== ', $self->title), "\n"; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# 1st gather active children and get width of prefix: |
79
|
16
|
|
|
|
|
73
|
$self->{_active} = []; |
80
|
16
|
|
|
|
|
53
|
while ($_ = $self->child) |
81
|
|
|
|
|
|
|
{ |
82
|
47
|
100
|
|
|
|
150
|
$_->can('_process') and push @{$self->{_active}}, $_; |
|
31
|
|
|
|
|
73
|
|
83
|
|
|
|
|
|
|
} |
84
|
16
|
|
|
|
|
18
|
$_ = @{$self->{_active}}; |
|
16
|
|
|
|
|
25
|
|
85
|
16
|
|
|
|
|
29
|
$_ = length($_); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# print children: |
88
|
16
|
|
|
|
|
32
|
my $pre_active = '<%' . $_ . 'd> '; |
89
|
16
|
|
|
|
|
27
|
my $pre_passive = ' ' x ($_ + 3); |
90
|
16
|
|
|
|
|
18
|
my $i = 1; |
91
|
16
|
|
|
|
|
32
|
while ($_ = $self->child) |
92
|
|
|
|
|
|
|
{ |
93
|
47
|
100
|
|
|
|
124
|
if ($_->can('_process')) |
94
|
31
|
|
|
|
|
122
|
{ $_->_show(sprintf($pre_active, $i++)); } |
95
|
|
|
|
|
|
|
else |
96
|
16
|
|
|
|
|
48
|
{ $_->_show($pre_passive); } |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# print standard selection strings: |
100
|
16
|
|
|
|
|
59
|
print $self->_wrap(sprintf($pre_active, 0), msg('leave_dialog')), "\n\n"; |
101
|
16
|
|
|
|
|
67
|
print $self->_wrap('----- ', msg('enter_number_to_choose_next_step')), ': '; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
######################################################################### |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 B<_process> - handle action of UI element |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$ui_element->_process; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head3 description: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Handle the action of the UI element. For a C's dialogue this |
113
|
|
|
|
|
|
|
means a loop of printing the dialogue's elements and allowing to select one |
114
|
|
|
|
|
|
|
of the active ones for processing until the dialogue is exited or destroyed. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _process($) |
121
|
|
|
|
|
|
|
{ |
122
|
7
|
|
|
7
|
|
3301
|
debug(3, __PACKAGE__, '::_process'); |
123
|
7
|
|
|
|
|
10
|
my ($self) = @_; |
124
|
7
|
|
|
|
|
12
|
local $_ = -1; |
125
|
|
|
|
|
|
|
|
126
|
7
|
|
|
|
|
9
|
while (1) |
127
|
|
|
|
|
|
|
{ |
128
|
16
|
100
|
|
|
|
76
|
if (defined $self->{_self_destruct}) |
129
|
5
|
|
|
|
|
23
|
{ $self->_self_destruct; return undef; } |
|
5
|
|
|
|
|
12
|
|
130
|
11
|
|
|
|
|
25
|
$self->_show; |
131
|
11
|
|
|
|
|
42
|
$_ = ; |
132
|
11
|
|
|
|
|
83
|
print $_; |
133
|
11
|
|
|
|
|
78
|
s/\r?\n$//; |
134
|
11
|
100
|
|
|
|
31
|
if ($_ eq '0') |
135
|
2
|
|
|
|
|
8
|
{ $self->destroy; return $_; } |
|
2
|
|
|
|
|
6
|
|
136
|
9
|
100
|
100
|
|
|
36
|
unless ($_ =~ m/^\d+$/ and $_ <= @{$self->{_active}}) |
|
6
|
|
|
|
|
22
|
|
137
|
4
|
|
|
|
|
13
|
{ error('invalid_selection'); $_ = -1; next; } |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
7
|
|
138
|
5
|
|
|
|
|
21
|
$self->{_active}->[$_-1]->_process; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
######################################################################### |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 B - remove dialogue from application |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
C's concrete implementation of |
147
|
|
|
|
|
|
|
L
|
148
|
|
|
|
|
|
|
from application> sets a flag for auto-destruction in C
|
149
|
|
|
|
|
|
|
- handle action of UI element>>. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub destroy($) |
156
|
|
|
|
|
|
|
{ |
157
|
6
|
|
|
6
|
1
|
653
|
debug(2, __PACKAGE__, '::destroy'); |
158
|
6
|
|
|
|
|
10
|
my ($self) = @_; |
159
|
6
|
|
|
|
|
13
|
$self->{_self_destruct} = 1; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
######################################################################### |
165
|
|
|
|
|
|
|
######################################################################### |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SEE ALSO |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
L, L |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright (C) Thomas Dorner. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
176
|
|
|
|
|
|
|
under the same terms as Perl itself. See LICENSE file for more details. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 AUTHOR |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Thomas Dorner Edorner (at) cpan (dot) orgE |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |