line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UI::Various::RichTerm::Button; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Author, Copyright and License: see end of file |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
UI::Various::RichTerm::Button - 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::Button; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 ABSTRACT |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module is the specific implementation of L using |
18
|
|
|
|
|
|
|
the rich terminal UI. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
The documentation of this module is only intended for developers of the |
23
|
|
|
|
|
|
|
package itself. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
######################################################################### |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
6
|
|
106
|
use v5.14; |
|
6
|
|
|
|
|
17
|
|
30
|
6
|
|
|
6
|
|
25
|
use strictures; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
24
|
|
31
|
6
|
|
|
6
|
|
748
|
no indirect 'fatal'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
142
|
|
32
|
6
|
|
|
6
|
|
287
|
no multidimensional; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
103
|
|
33
|
6
|
|
|
6
|
|
159
|
use warnings 'once'; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
247
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
36
|
|
|
|
|
|
|
|
37
|
6
|
|
|
6
|
|
26
|
use UI::Various::core; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
32
|
|
38
|
6
|
|
|
6
|
|
34
|
use UI::Various::Button; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
161
|
|
39
|
6
|
|
|
6
|
|
24
|
use UI::Various::RichTerm::base qw(%D); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
2042
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
require Exporter; |
42
|
|
|
|
|
|
|
our @ISA = qw(UI::Various::Button UI::Various::RichTerm::base); |
43
|
|
|
|
|
|
|
our @EXPORT_OK = qw(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
######################################################################### |
46
|
|
|
|
|
|
|
######################################################################### |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
######################################################################### |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 B<_prepare> - prepare UI element |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
($width, $height) = $ui_element->_prepare($content_width); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head3 example: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my ($w, $h) = $_->_prepare($content_width); |
61
|
|
|
|
|
|
|
$width < $w and $width = $w; |
62
|
|
|
|
|
|
|
$height += $h; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head3 parameters: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$content_width preferred width of content |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head3 description: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Prepare output of the UI element by determining and returning the space it |
71
|
|
|
|
|
|
|
wants or needs. I
|
72
|
|
|
|
|
|
|
C container elements!> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head3 returns: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
width and height the UI element will require or need when printed |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _prepare($$) |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
0
|
|
|
my ($self, $content_width) = @_; |
85
|
|
|
|
|
|
|
# Note that Button has 2 chars "special" decoration used in each line: |
86
|
0
|
|
|
|
|
|
my ($w, $h) = $self->_size($self->text, $content_width - 2); |
87
|
0
|
|
|
|
|
|
return ($w + 2, $h); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
######################################################################### |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 B<_show> - return formatted UI element |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$string = $ui_element->_show($prefix, $width, $height); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head3 example: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my ($w, $h) = $_->_prepare($content_width); |
99
|
|
|
|
|
|
|
... |
100
|
|
|
|
|
|
|
$_->_show('(1) ', $w, $h); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head3 parameters: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$prefix text in front of first line |
105
|
|
|
|
|
|
|
$width the width returned by _prepare above |
106
|
|
|
|
|
|
|
$height the height returned by _prepare above |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head3 description: |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Return the formatted (rectangular) text box of the UI element. Its height |
111
|
|
|
|
|
|
|
will be exactly as specified, unless there hasn't been enough space. The |
112
|
|
|
|
|
|
|
weight is similarly as specified plus the width needed for the prefix. |
113
|
|
|
|
|
|
|
I
|
114
|
|
|
|
|
|
|
elements!> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head3 returns: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
the rectangular text box for UI element |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _show($$$$) |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
0
|
|
|
my ($self, $prefix, $width, $height) = @_; |
127
|
|
|
|
|
|
|
return $self->_format($prefix, $D{BL}, '', $self->text, '', $D{BR}, |
128
|
0
|
|
|
|
|
|
$width - 2, $height); # - 2 chars decoration |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
######################################################################### |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 B<_process> - handle action of UI element |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$ui_element->_process; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head3 description: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Handle the action of the UI element aka I. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _process($) |
146
|
|
|
|
|
|
|
{ |
147
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
local $_ = $self->code; |
150
|
0
|
|
|
|
|
|
&$_($self->_toplevel, $self); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
######################################################################### |
156
|
|
|
|
|
|
|
######################################################################### |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L, L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright (C) Thomas Dorner. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
167
|
|
|
|
|
|
|
under the same terms as Perl itself. See LICENSE file for more details. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Thomas Dorner Edorner (at) cpan (dot) orgE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |