line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::RawInput; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# RawInput.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright (C) 2011-2023 |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# by Brian M. Kelly. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# You may distribute under the terms of the GNU Affero General |
10
|
|
|
|
|
|
|
# Public License, as specified in the LICENSE file. |
11
|
|
|
|
|
|
|
# . |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# http://www.fullautosoftware.net/ |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
## See user documentation at the end of this file. Search for =head |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = '1.24'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
611
|
use 5.006; |
|
1
|
|
|
|
|
9
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
## Module export. |
24
|
1
|
|
|
1
|
|
7
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
25
|
|
|
|
|
|
|
@EXPORT = qw(rawInput); |
26
|
|
|
|
|
|
|
## Module import. |
27
|
1
|
|
|
1
|
|
7
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
28
|
1
|
|
|
1
|
|
4
|
use Config (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
29
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
32
|
1
|
|
|
1
|
|
516
|
use Term::ReadKey; |
|
1
|
|
|
|
|
2099
|
|
|
1
|
|
|
|
|
130
|
|
33
|
1
|
|
|
1
|
|
570
|
use IO::Handle; |
|
1
|
|
|
|
|
6827
|
|
|
1
|
|
|
|
|
1581
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub rawInput { |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
0
|
|
my $length_prompt=length $_[0]; |
38
|
0
|
|
0
|
|
|
|
my $return_single=$_[1]||0; |
39
|
0
|
|
|
|
|
|
ReadMode('cbreak'); |
40
|
0
|
|
|
|
|
|
my $a=''; |
41
|
0
|
|
|
|
|
|
my $key=''; |
42
|
0
|
|
|
|
|
|
my @char=(); |
43
|
0
|
|
|
|
|
|
my $char=''; |
44
|
0
|
|
|
|
|
|
my $output=$_[0]; |
45
|
0
|
|
|
|
|
|
STDOUT->autoflush(1); |
46
|
0
|
0
|
0
|
|
|
|
if (exists $ENV{PARdir} && $^O eq 'cygwin') { |
47
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output."\n"); |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
STDOUT->autoflush(0); |
52
|
0
|
|
|
|
|
|
my $save=''; |
53
|
0
|
|
|
|
|
|
while (1) { |
54
|
0
|
|
|
|
|
|
$char=ReadKey(0); |
55
|
0
|
|
|
|
|
|
STDOUT->autoflush(1); |
56
|
0
|
|
|
|
|
|
$a=ord($char); |
57
|
0
|
|
|
|
|
|
push @char, $a; |
58
|
0
|
0
|
0
|
|
|
|
if ($a==10 || $a==13) { |
59
|
0
|
|
|
|
|
|
$save=$output; |
60
|
0
|
|
|
|
|
|
while (1) { |
61
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
62
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
63
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
64
|
0
|
|
|
|
|
|
chop $output; |
65
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
66
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$key='ENTER'; |
69
|
|
|
|
|
|
|
last |
70
|
0
|
|
|
|
|
|
} |
71
|
0
|
0
|
0
|
|
|
|
if ($a==127 || $a==8) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
return '','BACKSPACE' if $return_single; |
73
|
0
|
0
|
|
|
|
|
next if (length $output==$length_prompt); |
74
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
75
|
0
|
|
|
|
|
|
STDOUT->autoflush(1); |
76
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
77
|
0
|
|
|
|
|
|
STDOUT->autoflush(0); |
78
|
0
|
|
|
|
|
|
chop $output; |
79
|
0
|
|
|
|
|
|
STDOUT->autoflush(1); |
80
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
81
|
0
|
|
|
|
|
|
STDOUT->autoflush(0); |
82
|
|
|
|
|
|
|
} elsif ($a==27) { |
83
|
0
|
|
|
|
|
|
my $flag=0; |
84
|
0
|
|
|
|
|
|
while ($char=ReadKey(-1)) { |
85
|
0
|
|
|
|
|
|
$a=ord($char); |
86
|
0
|
|
|
|
|
|
push @char, $a; |
87
|
0
|
|
|
|
|
|
$flag++; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
0
|
|
|
|
|
unless ($flag) { |
90
|
0
|
|
|
|
|
|
while ($char=ReadKey(1)) { |
91
|
0
|
|
|
|
|
|
$a=ord($char); |
92
|
0
|
|
|
|
|
|
push @char, $a; |
93
|
0
|
|
|
|
|
|
$flag++; |
94
|
0
|
0
|
|
|
|
|
last if $flag==2; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
0
|
0
|
0
|
|
|
|
unless ($flag) { |
98
|
0
|
|
|
|
|
|
$key='ESC'; |
99
|
0
|
|
|
|
|
|
last; |
100
|
|
|
|
|
|
|
} elsif ($flag==1) { |
101
|
|
|
|
|
|
|
while ($char=ReadKey(1)) { |
102
|
|
|
|
|
|
|
$a=ord($char); |
103
|
|
|
|
|
|
|
push @char, $a; |
104
|
|
|
|
|
|
|
$flag++; |
105
|
|
|
|
|
|
|
last if $flag==2; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
0
|
0
|
|
|
|
|
if ($flag==2) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $e=$#char-2; |
110
|
0
|
0
|
|
|
|
|
if ($char[$e+1]==79) { |
|
|
0
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if ($char[$e+2]==80) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$key='F1'; |
113
|
|
|
|
|
|
|
} elsif ($char[$e+2]==81) { |
114
|
0
|
|
|
|
|
|
$key='F2'; |
115
|
|
|
|
|
|
|
} elsif ($char[$e+2]==82) { |
116
|
0
|
|
|
|
|
|
$key='F3'; |
117
|
|
|
|
|
|
|
} elsif ($char[$e+2]==83) { |
118
|
0
|
|
|
|
|
|
$key='F4'; |
119
|
|
|
|
|
|
|
} elsif ($char[$e+2]==115) { |
120
|
0
|
|
|
|
|
|
$key='PAGEDOWN'; |
121
|
|
|
|
|
|
|
} elsif ($char[$e+2]==121) { |
122
|
0
|
|
|
|
|
|
$key='PAGEUP'; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} elsif ($char[$e+1]==91) { |
125
|
0
|
0
|
|
|
|
|
if ($char[$e+2]==50) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$key='F9'; |
127
|
0
|
|
|
|
|
|
ReadKey(1); |
128
|
|
|
|
|
|
|
} elsif ($char[$e+2]==51) { |
129
|
0
|
|
|
|
|
|
$key='DELETE'; |
130
|
0
|
|
|
|
|
|
ReadKey(1); |
131
|
|
|
|
|
|
|
} elsif ($char[$e+2]==53) { |
132
|
0
|
|
|
|
|
|
$key='PAGEUP'; |
133
|
0
|
|
|
|
|
|
ReadKey(1); |
134
|
|
|
|
|
|
|
} elsif ($char[$e+2]==54) { |
135
|
0
|
|
|
|
|
|
$key='PAGEDOWN'; |
136
|
0
|
|
|
|
|
|
ReadKey(1); |
137
|
|
|
|
|
|
|
} elsif ($char[$e+2]==65) { |
138
|
0
|
|
|
|
|
|
$key='UPARROW'; |
139
|
0
|
|
|
|
|
|
while (ReadKey(-1)) { |
140
|
0
|
|
|
|
|
|
select(undef,undef,undef,0.5); |
141
|
0
|
|
|
|
|
|
last; |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
#ReadKey(1); |
144
|
|
|
|
|
|
|
} elsif ($char[$e+2]==66) { |
145
|
0
|
|
|
|
|
|
$key='DOWNARROW'; |
146
|
0
|
|
|
|
|
|
while (ReadKey(-1)) { |
147
|
0
|
|
|
|
|
|
select(undef,undef,undef,0.5); |
148
|
0
|
|
|
|
|
|
last; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
#ReadKey(1); |
151
|
|
|
|
|
|
|
} elsif ($char[$e+2]==67) { |
152
|
0
|
|
|
|
|
|
$key='RIGHTARROW'; |
153
|
|
|
|
|
|
|
} elsif ($char[$e+2]==68) { |
154
|
0
|
|
|
|
|
|
$key='LEFTARROW'; |
155
|
|
|
|
|
|
|
} elsif ($char[$e+2]==70) { |
156
|
0
|
|
|
|
|
|
$key='END'; |
157
|
|
|
|
|
|
|
} elsif ($char[$e+2]==72) { |
158
|
0
|
|
|
|
|
|
$key='HOME'; |
159
|
|
|
|
|
|
|
} |
160
|
0
|
0
|
|
|
|
|
if ($key) { |
161
|
0
|
|
|
|
|
|
$save=$output; |
162
|
0
|
|
|
|
|
|
while (1) { |
163
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
164
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
165
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
166
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
167
|
0
|
|
|
|
|
|
chop $output; |
168
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
169
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
170
|
|
|
|
|
|
|
} last |
171
|
0
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
0
|
0
|
|
|
|
|
if ($key) { |
174
|
0
|
|
|
|
|
|
$save=$output; |
175
|
0
|
|
|
|
|
|
while (1) { |
176
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
177
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
178
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
179
|
0
|
|
|
|
|
|
chop $output; |
180
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
181
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
182
|
|
|
|
|
|
|
} last |
183
|
0
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} elsif ($flag==3) { |
185
|
0
|
|
|
|
|
|
my $e=$#char-3; |
186
|
0
|
0
|
|
|
|
|
if ($char[$e+1]==91) { |
187
|
0
|
0
|
|
|
|
|
if ($char[$e+2]==49) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==126) { |
189
|
0
|
|
|
|
|
|
$key='HOME'; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} elsif ($char[$e+2]==50) { |
192
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==126) { |
193
|
0
|
|
|
|
|
|
$key='INSERT'; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} elsif ($char[$e+2]==51) { |
196
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==126) { |
197
|
0
|
|
|
|
|
|
$key='DELETE'; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} elsif ($char[$e+2]==52) { |
200
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==126) { |
201
|
0
|
|
|
|
|
|
$key='END'; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} elsif ($char[$e+2]==53) { |
204
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==126) { |
205
|
0
|
|
|
|
|
|
$key='PAGEUP'; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} elsif ($char[$e+2]==54) { |
208
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==126) { |
209
|
0
|
|
|
|
|
|
$key='PAGEDOWN'; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
0
|
0
|
|
|
|
|
if ($key) { |
214
|
0
|
|
|
|
|
|
$save=$output; |
215
|
0
|
|
|
|
|
|
while (1) { |
216
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
217
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
218
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
219
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
220
|
0
|
|
|
|
|
|
chop $output; |
221
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
222
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
223
|
|
|
|
|
|
|
} last |
224
|
0
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} elsif ($flag==4) { |
226
|
0
|
|
|
|
|
|
my $e=$#char-4; |
227
|
0
|
0
|
|
|
|
|
if ($char[$e+1]==91) { |
228
|
0
|
0
|
|
|
|
|
if ($char[$e+2]==49) { |
|
|
0
|
|
|
|
|
|
229
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==53) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
231
|
0
|
|
|
|
|
|
$key='F5'; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} elsif ($char[$e+3]==55) { |
234
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
235
|
0
|
|
|
|
|
|
$key='F6'; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
} elsif ($char[$e+3]==56) { |
238
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
239
|
0
|
|
|
|
|
|
$key='F7'; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} elsif ($char[$e+3]==57) { |
242
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
243
|
0
|
|
|
|
|
|
$key='F8'; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
} elsif ($char[$e+2]==50) { |
247
|
0
|
0
|
|
|
|
|
if ($char[$e+3]==48) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
248
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
249
|
0
|
|
|
|
|
|
$key='F9'; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
} elsif ($char[$e+3]==49) { |
252
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
253
|
0
|
|
|
|
|
|
$key='F10'; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} elsif ($char[$e+3]==51) { |
256
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
257
|
0
|
|
|
|
|
|
$key='F11'; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
} elsif ($char[$e+3]==52) { |
260
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
261
|
0
|
|
|
|
|
|
$key='F12'; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} elsif ($char[$e+3]==57) { |
264
|
0
|
0
|
|
|
|
|
if ($char[$e+4]==126) { |
265
|
0
|
|
|
|
|
|
$key='CONTEXT'; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
} |
271
|
0
|
0
|
|
|
|
|
if ($key) { |
272
|
0
|
|
|
|
|
|
$save=$output; |
273
|
0
|
|
|
|
|
|
while (1) { |
274
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
275
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
276
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
277
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
278
|
0
|
|
|
|
|
|
chop $output; |
279
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
280
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
281
|
|
|
|
|
|
|
} last |
282
|
0
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
} elsif ($return_single) { |
285
|
0
|
0
|
|
|
|
|
$key='TAB' if $a==9; |
286
|
0
|
|
|
|
|
|
$output.=chr($a); |
287
|
0
|
|
|
|
|
|
$save=$output; |
288
|
0
|
|
|
|
|
|
while (1) { |
289
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
290
|
0
|
|
|
|
|
|
substr($output,-1)=' '; |
291
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
292
|
0
|
|
|
|
|
|
chop $output; |
293
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
294
|
0
|
0
|
|
|
|
|
last if (length $output==$length_prompt); |
295
|
|
|
|
|
|
|
} last |
296
|
0
|
|
|
|
|
|
} else { |
297
|
0
|
|
|
|
|
|
$output.=chr($a); |
298
|
0
|
|
|
|
|
|
printf("\r% ${length_prompt}s",$output); |
299
|
|
|
|
|
|
|
} |
300
|
0
|
0
|
|
|
|
|
last unless defined $char; |
301
|
|
|
|
|
|
|
} |
302
|
0
|
|
|
|
|
|
substr($save,0,$length_prompt)=''; |
303
|
0
|
|
|
|
|
|
STDOUT->autoflush(0); |
304
|
0
|
|
|
|
|
|
ReadMode('normal'); |
305
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
|
return $save,$key; |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
1; |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
__END__; |