37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/flumtter/app/core/curses.rb', line 37
def getstr(win, ex=[])
buf = ""
x = win.curx
loop do
input = Dispel::Keyboard.translate_key_to_code(win.getch)
ex.each do |k|
return input if input == k
end
case input
when :"Ctrl+c"
raise CloseWindow
when :enter
return buf
when :escape
raise CloseWindow
when :left
if win.curx > x
win.setpos(win.cury, win.curx-1)
end
when :right
if win.curx <= buf.size
win.setpos(win.cury, win.curx+1)
end
when :backspace
buf.chop!
while win.curx > x
win.setpos(win.cury, win.curx-1)
win.delch()
win.insch(" ")
end
win.addstr(buf)
when String
buf << input.force_encoding("utf-8")
win.setpos(win.cury, win.curx)
win.addstr(input)
else
p input
end
end
rescue NoMethodError => e
if e.backtrace.shift =~ /keyboard.rb:210/
raise Dispel::Recall
else
raise e
end
end
|