4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/oschii/helpers/prompt.rb', line 4
def prompt(text, obscure: false)
print "#{text}: "
input = ''
char = ''
until !char.empty? && char.ord == 13
char = STDIN.getch
if char.ord == 127
input = input[0..-2]
print "\r#{text}: #{' ' * input.size} "
print "\r#{text}: #{obscure ? '*' * input.size : input}"
elsif char.ord == 27
raise CancelSerialQuery
elsif char.ord == 13
else
input += char
if obscure
print '*'
else
print char
end
end
end
puts
input
end
|