| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Goo::Prompter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
|
4
|
|
|
|
|
|
|
# Nigel Hamilton |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
|
7
|
|
|
|
|
|
|
# All Rights Reserved |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
|
10
|
|
|
|
|
|
|
# Filename: Goo::Prompter.pm |
|
11
|
|
|
|
|
|
|
# Description: Prompt the user for info. |
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
# Date Change |
|
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
15
|
|
|
|
|
|
|
# 06/02/2005 Auto generated file |
|
16
|
|
|
|
|
|
|
# 06/02/2005 Needed a modular way of doing this consistently |
|
17
|
|
|
|
|
|
|
# 06/03/2005 Added term completion |
|
18
|
|
|
|
|
|
|
# 10/08/2005 Added the ability to record a usage Trail - all user input |
|
19
|
|
|
|
|
|
|
# comes via the Prompter so it is a natural place to start. |
|
20
|
|
|
|
|
|
|
# 11/08/2005 Added method: askForKey |
|
21
|
|
|
|
|
|
|
# 08/11/2005 Added method: editText |
|
22
|
|
|
|
|
|
|
# 13/11/2005 Removed delegation to Prompter.pm - decided to trap actions |
|
23
|
|
|
|
|
|
|
# only - i may return to delegation if more information is |
|
24
|
|
|
|
|
|
|
# required for the GooTrail. The Trail recording in Thing.pm is |
|
25
|
|
|
|
|
|
|
# sufficient at the moment. |
|
26
|
|
|
|
|
|
|
# |
|
27
|
|
|
|
|
|
|
############################################################################### |
|
28
|
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
46
|
|
|
32
|
1
|
|
|
1
|
|
965
|
use Term::ReadKey; |
|
|
1
|
|
|
|
|
4816
|
|
|
|
1
|
|
|
|
|
96
|
|
|
33
|
1
|
|
|
1
|
|
943
|
use Term::Complete; |
|
|
1
|
|
|
|
|
1074
|
|
|
|
1
|
|
|
|
|
55
|
|
|
34
|
1
|
|
|
1
|
|
788
|
use Text::FormatTable; |
|
|
1
|
|
|
|
|
3129
|
|
|
|
1
|
|
|
|
|
39
|
|
|
35
|
1
|
|
|
1
|
|
1176
|
use Term::ANSIColor qw(:constants); |
|
|
1
|
|
|
|
|
8945
|
|
|
|
1
|
|
|
|
|
2569
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $title = BLACK ON_GREEN; |
|
38
|
|
|
|
|
|
|
my $highlight = WHITE; # select options in questions |
|
39
|
|
|
|
|
|
|
my $lowlight = BLUE; # informative options |
|
40
|
|
|
|
|
|
|
my $neonlight = GREEN; # BOLD! |
|
41
|
|
|
|
|
|
|
my $reset = RESET; # needed for interpolation |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $clear = ""; # keep a clear cache for faster clears |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
############################################################################### |
|
47
|
|
|
|
|
|
|
# |
|
48
|
|
|
|
|
|
|
# pick_command - pick a command from a list |
|
49
|
|
|
|
|
|
|
# |
|
50
|
|
|
|
|
|
|
############################################################################### |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub pick_command { |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
0
|
1
|
|
my ($commands, $default) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
0
|
|
|
|
$default = $default || ""; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# pull out all the command tokens - those that match [ |
|
59
|
0
|
|
|
|
|
|
my @commands = grep { $_ =~ /\[/ } split(/\s+/, $commands); |
|
|
0
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my %valid_options; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
foreach my $command (@commands) { |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my ($option) = $command =~ m/\[(.)\]/g; # grab the command [k]ey = k |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
next unless ($option); |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$command =~ s/\W//g; # remove the [] in the command word |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$valid_options{$option} = ucfirst(lc($command)); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# highlight the option in the question |
|
74
|
0
|
0
|
|
|
|
|
if ($option eq $default) { |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# highlight the keys in the question |
|
77
|
0
|
|
|
|
|
|
$commands =~ s/\[($option)/\[$neonlight$1/g; |
|
78
|
0
|
|
|
|
|
|
$commands =~ s/($option)\]/$1$reset\]/g; |
|
79
|
|
|
|
|
|
|
} else { |
|
80
|
0
|
|
|
|
|
|
$commands =~ s/\[($option)/\[$highlight$1/g; |
|
81
|
0
|
|
|
|
|
|
$commands =~ s/($option)\]/$1$reset\]/g; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
print $commands . ": "; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# wait for a valid keystroke |
|
88
|
0
|
|
|
|
|
|
while (my $key = get_key()) { |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# no command selected |
|
91
|
0
|
0
|
|
|
|
|
if ($key =~ /\n/) { |
|
92
|
0
|
|
|
|
|
|
say(); |
|
93
|
0
|
0
|
|
|
|
|
if ($default) { |
|
94
|
0
|
|
|
|
|
|
return $default; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
0
|
|
|
|
|
|
return ""; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# matches a lowercase key |
|
100
|
0
|
0
|
|
|
|
|
if ($key =~ /[a-z0-9]/) { |
|
101
|
0
|
|
|
|
|
|
say(); |
|
102
|
0
|
|
|
|
|
|
return $key; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# valid options |
|
107
|
0
|
0
|
|
|
|
|
if (exists $valid_options{$key}) { |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# go to a newline |
|
110
|
0
|
|
|
|
|
|
say(); |
|
111
|
0
|
|
|
|
|
|
return $key; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
############################################################################### |
|
119
|
|
|
|
|
|
|
# |
|
120
|
|
|
|
|
|
|
# pick_some - pick more than one answer to a question |
|
121
|
|
|
|
|
|
|
# |
|
122
|
|
|
|
|
|
|
############################################################################### |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub pick_some { |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
0
|
1
|
|
my ($question, @answers) = @_; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my @selected_answers; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
while (my $answer = pick_one($question, @answers)) { |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
say("Selected $answer."); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# remove this answer from the list |
|
135
|
0
|
|
|
|
|
|
@answers = grep { $_ ne $answer } @answers; |
|
|
0
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# remember the user selected it |
|
138
|
0
|
|
|
|
|
|
push(@selected_answers, $answer); |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return @selected_answers; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
############################################################################### |
|
148
|
|
|
|
|
|
|
# |
|
149
|
|
|
|
|
|
|
# pick_one - pick one from the list? |
|
150
|
|
|
|
|
|
|
# |
|
151
|
|
|
|
|
|
|
############################################################################### |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub pick_one { |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
0
|
1
|
|
my ($question, @answers) = @_; |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
$question =~ s/\?//g; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
print $question . " "; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $counter = 1; |
|
162
|
0
|
|
|
|
|
|
my $options = {}; |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
foreach my $answer (@answers) { |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
print "\n[", $highlight, $counter, RESET, "]$answer "; |
|
167
|
0
|
|
|
|
|
|
$options->{$counter} = $answer; |
|
168
|
0
|
|
|
|
|
|
$counter++; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
print "? "; |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
my $choice = get_response(); |
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
|
0
|
|
|
|
return $options->{$choice} || ""; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
############################################################################### |
|
181
|
|
|
|
|
|
|
# |
|
182
|
|
|
|
|
|
|
# confirm - yes or no? - default to "y"es |
|
183
|
|
|
|
|
|
|
# |
|
184
|
|
|
|
|
|
|
############################################################################### |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub confirm { |
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
0
|
1
|
|
my ($question, $default) = @_; |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
0
|
|
|
|
$default = $default || "Y"; |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
$question =~ s/\s+$//; |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
0
|
|
|
|
|
my $yes_or_no = $default eq "Y" ? "Y/n" : "y/N"; |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
print $question . " [", $highlight, $yes_or_no, RESET, "] "; |
|
197
|
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $answer = get_response(); |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# if no specific answer then set to default |
|
201
|
0
|
0
|
|
|
|
|
if (not $answer) { $answer = $default; } |
|
|
0
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# if the answer matches yes then confirm |
|
204
|
0
|
|
|
|
|
|
return $answer =~ /^[Yy]/; |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
############################################################################### |
|
209
|
|
|
|
|
|
|
# |
|
210
|
|
|
|
|
|
|
# insist - ask a question and insist on an answer |
|
211
|
|
|
|
|
|
|
# |
|
212
|
|
|
|
|
|
|
############################################################################### |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub insist { |
|
215
|
|
|
|
|
|
|
|
|
216
|
0
|
|
|
0
|
1
|
|
my ($question) = @_; |
|
217
|
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
while (1) { |
|
219
|
0
|
|
|
|
|
|
my $response = ask($question); |
|
220
|
0
|
0
|
|
|
|
|
if ($response ne "") { |
|
221
|
0
|
|
|
|
|
|
return $response; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
############################################################################### |
|
228
|
|
|
|
|
|
|
# |
|
229
|
|
|
|
|
|
|
# ask - ask a question |
|
230
|
|
|
|
|
|
|
# |
|
231
|
|
|
|
|
|
|
############################################################################### |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub ask { |
|
234
|
|
|
|
|
|
|
|
|
235
|
0
|
|
|
0
|
1
|
|
my ($question, $default_answer) = @_; |
|
236
|
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
$question =~ s/\s+$//; |
|
238
|
0
|
|
|
|
|
|
print $question . " "; |
|
239
|
|
|
|
|
|
|
|
|
240
|
0
|
0
|
|
|
|
|
if ($default_answer) { |
|
241
|
0
|
|
|
|
|
|
print "[$default_answer] "; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
|
|
244
|
0
|
|
0
|
|
|
|
return get_response() || $default_answer || ""; |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
############################################################################### |
|
249
|
|
|
|
|
|
|
# |
|
250
|
|
|
|
|
|
|
# keep_asking - keep asking the same question |
|
251
|
|
|
|
|
|
|
# |
|
252
|
|
|
|
|
|
|
############################################################################### |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub keep_asking { |
|
255
|
|
|
|
|
|
|
|
|
256
|
0
|
|
|
0
|
1
|
|
my ($question) = @_; |
|
257
|
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
my @answers; |
|
259
|
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
while (1) { |
|
261
|
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
print $question. " "; |
|
263
|
|
|
|
|
|
|
|
|
264
|
0
|
0
|
|
|
|
|
if (scalar(@answers) > 0) { |
|
265
|
0
|
|
|
|
|
|
print " [", $lowlight, join(', ', @answers), RESET, "] "; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
|
|
268
|
0
|
|
|
|
|
|
my $answer = get_response(); |
|
269
|
0
|
0
|
|
|
|
|
if ($answer eq "") { last; } |
|
|
0
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
|
push(@answers, $answer); |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
return @answers; |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
############################################################################### |
|
279
|
|
|
|
|
|
|
# |
|
280
|
|
|
|
|
|
|
# say - say something |
|
281
|
|
|
|
|
|
|
# |
|
282
|
|
|
|
|
|
|
############################################################################### |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub say { |
|
285
|
|
|
|
|
|
|
|
|
286
|
0
|
|
|
0
|
1
|
|
my ($something) = @_; |
|
287
|
|
|
|
|
|
|
|
|
288
|
0
|
|
0
|
|
|
|
$something = $something || ""; |
|
289
|
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
|
print $something . "\n"; |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
############################################################################### |
|
296
|
|
|
|
|
|
|
# |
|
297
|
|
|
|
|
|
|
# show_title - say something on a green background! - this is the goo! |
|
298
|
|
|
|
|
|
|
# |
|
299
|
|
|
|
|
|
|
############################################################################### |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub show_title { |
|
302
|
|
|
|
|
|
|
|
|
303
|
0
|
|
|
0
|
1
|
|
my ($something) = @_; |
|
304
|
|
|
|
|
|
|
|
|
305
|
0
|
|
|
|
|
|
print $title . $something . $reset . "\n"; |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
} |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
############################################################################### |
|
310
|
|
|
|
|
|
|
# |
|
311
|
|
|
|
|
|
|
# stop - do a die |
|
312
|
|
|
|
|
|
|
# |
|
313
|
|
|
|
|
|
|
############################################################################### |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
sub stop { |
|
316
|
|
|
|
|
|
|
|
|
317
|
0
|
|
|
0
|
1
|
|
my ($reason) = @_; |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
# say it in NEON |
|
320
|
0
|
|
|
|
|
|
yell($reason); |
|
321
|
0
|
|
|
|
|
|
exit; |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
} |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
############################################################################### |
|
327
|
|
|
|
|
|
|
# |
|
328
|
|
|
|
|
|
|
# clear - clear the screen |
|
329
|
|
|
|
|
|
|
# |
|
330
|
|
|
|
|
|
|
############################################################################### |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
sub clear { |
|
333
|
|
|
|
|
|
|
|
|
334
|
0
|
0
|
|
0
|
1
|
|
if ($clear) { |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# re-use if cached |
|
337
|
0
|
|
|
|
|
|
print $clear; |
|
338
|
|
|
|
|
|
|
} else { |
|
339
|
0
|
|
|
|
|
|
$clear = system("/usr/bin/clear"); |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
} |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
############################################################################### |
|
344
|
|
|
|
|
|
|
# |
|
345
|
|
|
|
|
|
|
# yell - say something loudly!!! |
|
346
|
|
|
|
|
|
|
# |
|
347
|
|
|
|
|
|
|
############################################################################### |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub yell { |
|
350
|
|
|
|
|
|
|
|
|
351
|
0
|
|
|
0
|
1
|
|
my ($something) = @_; |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
# say it in NEON |
|
354
|
0
|
|
|
|
|
|
say($neonlight . $something . RESET); |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
} |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
############################################################################### |
|
360
|
|
|
|
|
|
|
# |
|
361
|
|
|
|
|
|
|
# highlight_options - take a string and highlight any options you find |
|
362
|
|
|
|
|
|
|
# |
|
363
|
|
|
|
|
|
|
############################################################################### |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
sub highlight_options { |
|
366
|
|
|
|
|
|
|
|
|
367
|
0
|
|
|
0
|
1
|
|
my ($string) = @_; |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# highlight everything after [ |
|
370
|
0
|
|
|
|
|
|
$string =~ s/\[/\[$highlight/g; |
|
371
|
0
|
|
|
|
|
|
$string =~ s/\]/$reset\]/g; |
|
372
|
|
|
|
|
|
|
|
|
373
|
0
|
|
|
|
|
|
return $string; |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
} |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
############################################################################### |
|
379
|
|
|
|
|
|
|
# |
|
380
|
|
|
|
|
|
|
# trace - debugging aid |
|
381
|
|
|
|
|
|
|
# |
|
382
|
|
|
|
|
|
|
############################################################################### |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub trace { |
|
385
|
|
|
|
|
|
|
|
|
386
|
0
|
|
|
0
|
1
|
|
my ($message) = @_; |
|
387
|
|
|
|
|
|
|
|
|
388
|
0
|
|
|
|
|
|
notify(caller() . " - $message"); |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
############################################################################### |
|
394
|
|
|
|
|
|
|
# |
|
395
|
|
|
|
|
|
|
# dump - debugging aid |
|
396
|
|
|
|
|
|
|
# |
|
397
|
|
|
|
|
|
|
############################################################################### |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub dump { |
|
400
|
|
|
|
|
|
|
|
|
401
|
0
|
|
|
0
|
1
|
|
my ($variable) = @_; |
|
402
|
|
|
|
|
|
|
|
|
403
|
0
|
|
|
|
|
|
trace(Dumper($variable)); |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
} |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
############################################################################### |
|
409
|
|
|
|
|
|
|
# |
|
410
|
|
|
|
|
|
|
# prompt - prompt for something loudly!!! |
|
411
|
|
|
|
|
|
|
# |
|
412
|
|
|
|
|
|
|
############################################################################### |
|
413
|
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
sub prompt { |
|
415
|
|
|
|
|
|
|
|
|
416
|
0
|
|
|
0
|
1
|
|
my ($prompt) = @_; |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
# say it in NEON |
|
419
|
0
|
|
|
|
|
|
print $neonlight . $prompt . RESET . "> "; |
|
420
|
|
|
|
|
|
|
|
|
421
|
0
|
|
|
|
|
|
return get_response(); |
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
} |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
############################################################################### |
|
426
|
|
|
|
|
|
|
# |
|
427
|
|
|
|
|
|
|
# notify - say something and pause for a while |
|
428
|
|
|
|
|
|
|
# |
|
429
|
|
|
|
|
|
|
############################################################################### |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
sub notify { |
|
432
|
|
|
|
|
|
|
|
|
433
|
0
|
|
|
0
|
1
|
|
my ($string) = @_; |
|
434
|
|
|
|
|
|
|
|
|
435
|
0
|
|
|
|
|
|
say($string); |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
# pause for a keystroke |
|
438
|
0
|
|
|
|
|
|
get_key(); |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
} |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
############################################################################### |
|
443
|
|
|
|
|
|
|
# |
|
444
|
|
|
|
|
|
|
# get_key - return a single keystroke |
|
445
|
|
|
|
|
|
|
# |
|
446
|
|
|
|
|
|
|
############################################################################### |
|
447
|
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
sub get_key { |
|
449
|
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
# see recipe 15.6 Perl Cookbook |
|
451
|
0
|
|
|
0
|
1
|
|
ReadMode('cbreak'); |
|
452
|
0
|
|
|
|
|
|
my $char = ReadKey(0); |
|
453
|
0
|
|
|
|
|
|
ReadMode('normal'); |
|
454
|
0
|
|
|
|
|
|
return $char; |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
} |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
############################################################################### |
|
459
|
|
|
|
|
|
|
# |
|
460
|
|
|
|
|
|
|
# ask_with_completion - ask with tab completion - <cntrl d> for a list of possibles |
|
461
|
|
|
|
|
|
|
# |
|
462
|
|
|
|
|
|
|
############################################################################### |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub ask_with_completion { |
|
465
|
|
|
|
|
|
|
|
|
466
|
0
|
|
|
0
|
1
|
|
my ($question, @list) = @_; |
|
467
|
|
|
|
|
|
|
|
|
468
|
0
|
|
|
|
|
|
return Complete($question, @list); |
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
} |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
############################################################################### |
|
473
|
|
|
|
|
|
|
# |
|
474
|
|
|
|
|
|
|
# get_response - return a response |
|
475
|
|
|
|
|
|
|
# |
|
476
|
|
|
|
|
|
|
############################################################################### |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
sub get_response { |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
# restore line reading mode - turned off by WebDBLite? |
|
481
|
0
|
|
|
0
|
1
|
|
$/ = "\n"; |
|
482
|
|
|
|
|
|
|
|
|
483
|
0
|
|
|
|
|
|
my $response = <STDIN>; |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
# strip leading and trailing spaces |
|
486
|
0
|
|
|
|
|
|
$response =~ s/^\s+//g; |
|
487
|
0
|
|
|
|
|
|
$response =~ s/\s+$//g; |
|
488
|
|
|
|
|
|
|
|
|
489
|
0
|
|
|
|
|
|
return $response; |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
############################################################################### |
|
494
|
|
|
|
|
|
|
# |
|
495
|
|
|
|
|
|
|
# ask_for_key - prompt for a single key |
|
496
|
|
|
|
|
|
|
# |
|
497
|
|
|
|
|
|
|
############################################################################### |
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub ask_for_key { |
|
500
|
|
|
|
|
|
|
|
|
501
|
0
|
|
|
0
|
1
|
|
my ($question) = @_; |
|
502
|
|
|
|
|
|
|
|
|
503
|
0
|
|
|
|
|
|
print $question . " "; |
|
504
|
|
|
|
|
|
|
|
|
505
|
0
|
|
|
|
|
|
my $key = get_key(); |
|
506
|
|
|
|
|
|
|
|
|
507
|
0
|
|
|
|
|
|
print "\n"; |
|
508
|
|
|
|
|
|
|
|
|
509
|
0
|
|
|
|
|
|
return $key; |
|
510
|
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
1; |
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
__END__ |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=head1 NAME |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
Goo::Prompter - Prompt the user for info. |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
use Goo::Prompter; |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
=head1 METHODS |
|
529
|
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
=over |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=item pick_command |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
pick a command from a list |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=item pick_some |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
pick more than one answer to a question |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
=item pick_one |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
pick one from the list? |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=item confirm |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
yes or no? - default to "y"es |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
=item insist |
|
549
|
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
ask a question and insist on an answer |
|
551
|
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
=item ask |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
ask a question |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=item keep_asking |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
keep asking the same question |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=item say |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
say something like in Perl6 |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
=item show_title |
|
565
|
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
say something on a green background! - this is The Goo! |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=item stop |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
say something and then stop |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
=item clear |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
clear the screen |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
=item yell |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
say something loudly!!! |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
=item highlight_options |
|
581
|
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
take a string and highlight any options you find |
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
=item trace |
|
585
|
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
print a trace message as a debugging aid |
|
587
|
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
=item dump |
|
589
|
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
use Data::Dumper to show the contents of a variable |
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
=item prompt |
|
593
|
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
prompt for something loudly!!! |
|
595
|
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
=item notify |
|
597
|
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
say something and pause for a while |
|
599
|
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
=item get_key |
|
601
|
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
return a single keystroke |
|
603
|
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
=item ask_with_completion |
|
605
|
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
ask with tab completion - <cntrl d> shows a list of possible alternatives |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=item get_response |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
return a response |
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
=item ask_for_key |
|
613
|
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
prompt for a single key |
|
615
|
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=back |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
=head1 AUTHOR |
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
|
621
|
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
623
|
|
|
|
|
|
|
|