10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/make_menu/console/prompter.rb', line 10
def self.prompt(text = '', obscure: false)
print text
input = ''
char = ''
until !char.empty? && char.ord == 13
char = $stdin.getch
case char.ord
when 127
input = input[0..-2]
print "\r#{text}#{' ' * input.size} "
print "\r#{text}#{obscure ? '*' * input.size : input}"
when 27
raise PressedEscape
when 13
else
input += char
if obscure
print '*'
else
print char
end
end
end
input
end
|