line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::GentooFunctions; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.006001; |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
20773
|
use strict; |
|
6
|
|
|
|
|
34
|
|
|
6
|
|
|
|
|
143
|
|
6
|
6
|
|
|
6
|
|
2752
|
use utf8; |
|
6
|
|
|
|
|
69
|
|
|
6
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
6
|
|
|
6
|
|
592
|
eval "use Term::Size;"; my $old = $@; |
|
6
|
|
|
6
|
|
15
|
|
|
6
|
|
|
|
|
2120
|
|
|
6
|
|
|
|
|
12064
|
|
|
6
|
|
|
|
|
162
|
|
10
|
6
|
50
|
|
|
|
19
|
eval "use Term::Size::Win32" if $old; my $new = $@; |
|
6
|
|
|
|
|
11
|
|
11
|
6
|
50
|
33
|
|
|
48
|
die $old if $old and $new; |
12
|
6
|
50
|
|
|
|
122
|
die $new if $new; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
|
32
|
use Exporter; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
175
|
|
16
|
6
|
|
|
6
|
|
2950
|
use Term::ANSIColor qw(:constants); |
|
6
|
|
|
|
|
47434
|
|
|
6
|
|
|
|
|
5328
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.3700'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw(einfo eerror ewarn ebegin eend eindent eoutdent einfon edie edo start_spinner step_spinner end_spinner equiet); |
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all=>[@EXPORT_OK]); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $is_spinning = 0; |
24
|
|
|
|
|
|
|
my $post_spin_lines = 0; |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
6
|
|
43
|
use base qw(Exporter); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1350
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Lifted from Term::ANSIScreen (RT #123497) |
29
|
|
|
|
|
|
|
# -- Sawyer X |
30
|
|
|
|
|
|
|
our $AUTORESET; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Lifted and adjusted from Term::ANSIScreen (RT #123497) |
33
|
|
|
|
|
|
|
# -- Sawyer X |
34
|
|
|
|
|
|
|
BEGIN { |
35
|
6
|
|
|
6
|
|
104
|
my %attributes = ( |
36
|
|
|
|
|
|
|
'clear' => 0, 'reset' => 0, |
37
|
|
|
|
|
|
|
'bold' => 1, 'dark' => 2, |
38
|
|
|
|
|
|
|
'underline' => 4, 'underscore' => 4, |
39
|
|
|
|
|
|
|
'blink' => 5, 'reverse' => 7, |
40
|
|
|
|
|
|
|
'concealed' => 8, |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
'black' => 30, 'on_black' => 40, |
43
|
|
|
|
|
|
|
'red' => 31, 'on_red' => 41, |
44
|
|
|
|
|
|
|
'green' => 32, 'on_green' => 42, |
45
|
|
|
|
|
|
|
'yellow' => 33, 'on_yellow' => 43, |
46
|
|
|
|
|
|
|
'blue' => 34, 'on_blue' => 44, |
47
|
|
|
|
|
|
|
'magenta' => 35, 'on_magenta' => 45, |
48
|
|
|
|
|
|
|
'cyan' => 36, 'on_cyan' => 46, |
49
|
|
|
|
|
|
|
'white' => 37, 'on_white' => 47, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
66
|
my %sequences = ( |
53
|
|
|
|
|
|
|
'up' => '?A', 'down' => '?B', |
54
|
|
|
|
|
|
|
'right' => '?C', 'left' => '?D', |
55
|
|
|
|
|
|
|
'savepos' => 's', 'loadpos' => 'u', |
56
|
|
|
|
|
|
|
'cls' => '2J', 'clline' => 'K', |
57
|
|
|
|
|
|
|
'cldown' => '0J', 'clup' => '1J', |
58
|
|
|
|
|
|
|
'locate' => '?;?H', 'setmode' => '?h', |
59
|
|
|
|
|
|
|
'wrapon' => '7h', 'wrapoff' => '7l', |
60
|
|
|
|
|
|
|
'setscroll' => '?;?r', |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
21
|
my $enable_colors = !defined $ENV{ANSI_COLORS_DISABLED}; |
64
|
6
|
|
|
6
|
|
34
|
no strict 'refs'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
205
|
|
65
|
6
|
|
|
6
|
|
29
|
no warnings 'uninitialized'; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2012
|
|
66
|
|
|
|
|
|
|
|
67
|
6
|
|
|
|
|
22
|
foreach my $sub ( keys %sequences ) { |
68
|
90
|
|
|
|
|
128
|
my $seq = $sequences{$sub}; |
69
|
90
|
|
|
|
|
358
|
*{"Term::GentooFunctions::$sub"} = sub { |
70
|
10
|
50
|
|
10
|
|
22
|
return '' unless $enable_colors; |
71
|
|
|
|
|
|
|
|
72
|
10
|
50
|
|
|
|
23
|
$seq =~ s/\?/defined($_[0]) ? shift(@_) : 1/eg; |
|
4
|
|
|
|
|
16
|
|
73
|
10
|
50
|
|
|
|
37
|
return((defined wantarray) ? "\e[$seq" |
74
|
|
|
|
|
|
|
: print("\e[$seq")); |
75
|
90
|
|
|
|
|
276
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
6
|
|
|
|
|
41
|
foreach my $sub ( keys %attributes ) { |
79
|
150
|
|
|
|
|
232
|
my $attr = $attributes{lc($sub)}; |
80
|
150
|
|
|
|
|
229
|
my $sub_name = uc($sub); |
81
|
150
|
|
|
|
|
721
|
*{"Term::GentooFunctions::$sub_name"} = sub { |
82
|
76
|
50
|
33
|
76
|
|
269
|
if (defined($attr) and $sub_name =~ /^[A-Z_]+$/) { |
83
|
76
|
|
|
|
|
118
|
my $out = "@_"; |
84
|
76
|
50
|
|
|
|
112
|
if ($enable_colors) { |
85
|
76
|
|
|
|
|
128
|
$out = "\e[${attr}m" . $out; |
86
|
76
|
0
|
33
|
|
|
136
|
$out .= "\e[0m" if ($AUTORESET and @_ and $out !~ /\e\[0m$/s); |
|
|
|
33
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
76
|
50
|
|
|
|
458
|
return((defined wantarray) ? $out |
89
|
|
|
|
|
|
|
: print($out)); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
0
|
|
|
|
|
0
|
require Carp; |
93
|
0
|
|
|
|
|
0
|
Carp::croak("Undefined subroutine &$sub ($sub_name) called"); |
94
|
|
|
|
|
|
|
} |
95
|
150
|
|
|
|
|
504
|
}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
BEGIN { |
100
|
|
|
|
|
|
|
# use Data::Dumper; |
101
|
|
|
|
|
|
|
# die Dumper(\%ENV) unless defined $ENV{RC_INDENTATION}; |
102
|
6
|
50
|
|
6
|
|
58
|
$ENV{RC_DEFAULT_INDENT} = 2 unless defined $ENV{RC_DEFAULT_INDENT}; |
103
|
6
|
50
|
|
|
|
6424
|
$ENV{RC_INDENTATION} = "" unless defined $ENV{RC_INDENTATION}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $quiet; |
107
|
|
|
|
|
|
|
sub equiet { |
108
|
1
|
50
|
|
1
|
0
|
314
|
$quiet = $_[0] if @_; |
109
|
1
|
|
|
|
|
2
|
return $quiet; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub edie(@) { |
113
|
0
|
0
|
|
0
|
0
|
0
|
my $msg = (@_>0 ? shift : $_); |
114
|
0
|
|
|
|
|
0
|
eerror($msg); |
115
|
0
|
0
|
|
|
|
0
|
_pre_print_during_spin() if $is_spinning; |
116
|
0
|
|
|
|
|
0
|
$is_spinning = 0; |
117
|
0
|
|
|
|
|
0
|
eend(0); |
118
|
0
|
|
|
|
|
0
|
exit 0x65; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub einfon($) { |
122
|
0
|
|
|
0
|
0
|
0
|
my $msg = wash(shift); |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
0
|
return if $quiet; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
0
|
local $| = 1; |
127
|
0
|
|
|
|
|
0
|
print " ", BOLD, GREEN, "*", RESET, $msg; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub eindent() { |
131
|
6
|
|
33
|
6
|
0
|
40
|
my $i = shift || $ENV{RC_DEFAULT_INDENT}; |
132
|
|
|
|
|
|
|
|
133
|
6
|
|
|
|
|
32
|
$ENV{RC_INDENTATION} .= " " x $i; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub eoutdent() { |
137
|
34
|
|
33
|
34
|
0
|
105
|
my $i = shift || $ENV{RC_DEFAULT_INDENT}; |
138
|
|
|
|
|
|
|
|
139
|
34
|
|
|
|
|
116
|
$ENV{RC_INDENTATION} =~ s/ // for 1 .. $i; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub wash($) { |
143
|
18
|
|
|
18
|
0
|
30
|
my $msg = shift; |
144
|
18
|
|
|
|
|
40
|
$msg =~ s/^\s+//s; |
145
|
|
|
|
|
|
|
|
146
|
18
|
|
|
|
|
26
|
chomp $msg; |
147
|
18
|
|
|
|
|
48
|
return "$ENV{RC_INDENTATION} $msg"; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub einfo($) { |
151
|
15
|
|
|
15
|
0
|
326
|
my $msg = wash(shift); |
152
|
|
|
|
|
|
|
|
153
|
15
|
100
|
|
|
|
36
|
return if $quiet; |
154
|
14
|
50
|
|
|
|
24
|
_pre_print_during_spin() if $is_spinning; |
155
|
14
|
|
|
|
|
21
|
print " ", BOLD, GREEN, "*", RESET, "$msg\n"; |
156
|
14
|
50
|
|
|
|
61
|
_post_print_during_spin() if $is_spinning; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub ebegin($) { |
160
|
6
|
|
|
6
|
0
|
314
|
goto &einfo; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub eerror($) { |
164
|
1
|
|
|
1
|
0
|
4
|
my $msg = wash(shift); |
165
|
|
|
|
|
|
|
|
166
|
1
|
50
|
|
|
|
3
|
return if $quiet; |
167
|
1
|
50
|
|
|
|
9
|
_pre_print_during_spin() if $is_spinning; |
168
|
1
|
|
|
|
|
3
|
print " ", BOLD, RED, "*", RESET, "$msg\n"; |
169
|
1
|
50
|
|
|
|
6
|
_post_print_during_spin() if $is_spinning; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub ewarn($) { |
173
|
2
|
|
|
2
|
0
|
9
|
my $msg = wash(shift); |
174
|
|
|
|
|
|
|
|
175
|
2
|
50
|
|
|
|
7
|
return if $quiet; |
176
|
2
|
50
|
|
|
|
12
|
_pre_print_during_spin() if $is_spinning; |
177
|
2
|
|
|
|
|
7
|
print " ", BOLD, YELLOW, "*", RESET, "$msg\n"; |
178
|
2
|
50
|
|
|
|
12
|
_post_print_during_spin() if $is_spinning; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub eend(@) { |
182
|
6
|
100
|
|
6
|
0
|
29
|
my $res = (@_>0 ? shift : $_); |
183
|
|
|
|
|
|
|
|
184
|
6
|
100
|
|
|
|
12
|
return if $quiet; |
185
|
|
|
|
|
|
|
|
186
|
5
|
|
|
|
|
295
|
my ($columns, $rows) = eval 'Term::Size::chars *STDOUT{IO}'; |
187
|
5
|
50
|
|
|
|
22
|
($columns, $rows) = eval 'Term::Size::Win32::chars *STDOUT{IO}' if $@; |
188
|
|
|
|
|
|
|
|
189
|
5
|
50
|
|
|
|
10
|
die "couldn't find a term size function to use" if $@; |
190
|
|
|
|
|
|
|
|
191
|
5
|
100
|
|
|
|
13
|
print up(1), right($columns - 6), BOLD, BLUE, "[ ", |
192
|
|
|
|
|
|
|
($res ? GREEN."ok" : RED."!!"), |
193
|
|
|
|
|
|
|
BLUE, " ]", RESET, "\n"; |
194
|
|
|
|
|
|
|
|
195
|
5
|
|
|
|
|
25
|
$res; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub edo($&) { |
199
|
1
|
|
|
1
|
0
|
8
|
my ($begin_msg, $code) = @_; |
200
|
|
|
|
|
|
|
|
201
|
1
|
|
|
|
|
3
|
ebegin $begin_msg; |
202
|
1
|
|
|
|
|
3
|
eindent; |
203
|
1
|
|
|
|
|
1
|
my ($cr, @cr); |
204
|
|
|
|
|
|
|
|
205
|
1
|
|
|
|
|
3
|
my $wa = wantarray; |
206
|
1
|
50
|
|
|
|
1
|
my $r = eval { if( $wa ) { @cr = $code->() } else { $cr = $code->() } 1 }; |
|
1
|
|
|
|
|
3
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
207
|
1
|
50
|
|
|
|
3
|
edie $@ unless $r; |
208
|
|
|
|
|
|
|
|
209
|
1
|
|
|
|
|
2
|
eoutdent; |
210
|
1
|
|
|
|
|
3
|
eend 1; |
211
|
|
|
|
|
|
|
|
212
|
1
|
50
|
|
|
|
3
|
return @cr if $wa; |
213
|
1
|
|
|
|
|
3
|
return $cr; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _pre_print_during_spin { |
217
|
0
|
0
|
|
0
|
|
|
return if $post_spin_lines < 0; # when does this happen?? totally untested condition XXX |
218
|
|
|
|
|
|
|
|
219
|
0
|
0
|
|
|
|
|
if( $post_spin_lines == 0 ) { |
220
|
0
|
|
|
|
|
|
print "\n"; |
221
|
0
|
|
|
|
|
|
$post_spin_lines ++; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
print down($post_spin_lines++), "\e[0G\e[K"; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub _post_print_during_spin { |
228
|
0
|
|
|
0
|
|
|
local $| = 1; |
229
|
0
|
|
|
|
|
|
print up($post_spin_lines); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
{ |
233
|
|
|
|
|
|
|
my $spinner_state; |
234
|
|
|
|
|
|
|
my $spinner_msg; |
235
|
|
|
|
|
|
|
sub start_spinner($) { |
236
|
0
|
|
|
0
|
0
|
|
my $msg = wash(shift); |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
$spinner_state = "-"; |
239
|
0
|
|
|
|
|
|
$spinner_msg = $msg; |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$is_spinning = 1; |
242
|
0
|
|
|
|
|
|
$post_spin_lines = 0; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
einfon $spinner_msg; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
my $spinext = {"-"=>'\\', '\\'=>'|', "|"=>"/", "/"=>"-"}; |
248
|
|
|
|
|
|
|
sub step_spinner(;$) { |
249
|
|
|
|
|
|
|
# NOTE: really I should use savepost and clline from ANSIScreen, but he doesn't have [0G at all. Meh |
250
|
|
|
|
|
|
|
|
251
|
0
|
0
|
|
0
|
0
|
|
return if $quiet; |
252
|
0
|
|
|
|
|
|
print "\e[0G\e[K"; |
253
|
|
|
|
|
|
|
|
254
|
0
|
0
|
|
|
|
|
if( $_[0] ) { |
255
|
0
|
|
|
|
|
|
einfon("$spinner_msg $spinner_state ... $_[0]"); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
} else { |
258
|
0
|
|
|
|
|
|
einfon("$spinner_msg $spinner_state "); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
|
$spinner_state = $spinext->{$spinner_state}; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub end_spinner($) { |
265
|
0
|
0
|
|
0
|
0
|
|
return if $quiet; |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
$is_spinning = 0; |
268
|
0
|
|
|
|
|
|
print "\e[0G\e[K"; |
269
|
0
|
|
|
|
|
|
einfo $spinner_msg; |
270
|
0
|
|
|
|
|
|
$post_spin_lines --; |
271
|
0
|
|
|
|
|
|
_pre_print_during_spin(); |
272
|
0
|
|
|
|
|
|
$post_spin_lines = 0; |
273
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
goto &eend; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
END { |
278
|
6
|
50
|
|
6
|
|
61612
|
if( $is_spinning ) { |
279
|
0
|
|
|
|
|
0
|
$is_spinning = 0; |
280
|
0
|
|
|
|
|
0
|
print "\e[0G\e[K"; |
281
|
0
|
|
|
|
|
0
|
einfo $spinner_msg; |
282
|
0
|
|
|
|
|
0
|
$post_spin_lines --; |
283
|
0
|
|
|
|
|
0
|
_pre_print_during_spin(); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
"this file is true"; |