18 def self.readline(prompt)
23 @c_erase, @c_kill, @c_quit, @c_intr = _terminal_raw
36 code = ASCII::Erase if code == @c_erase
40 if code == ASCII::Return
43 elsif code == ASCII::ControlD
47 puts "", "<Control-C>"
48 raise Interrupt, "User requested termination with Control-C"
49 elsif code == ASCII::Erase
54 print str.join(""), " ", "\b" * (str.size + 1 - idx)
56 elsif code == ASCII::Escape
57 STDIN.read(1) # eat the [
58 command = STDIN.read(1)
59 input = "\e[" + command
64 if @history_idx == @history.size && str.size > 0
70 print "\b" * idx, " " * str.size, "\b" * str.size
71 str = @history[@history_idx].dup
77 if @history_idx < @history.size
80 print "\b" * idx, " " * str.size, "\b" * str.size
81 str = (@history[@history_idx] || []).dup
100 elsif code == ASCII::Home
103 elsif code == ASCII::End
104 print "\b" * idx, str.join("")
108 print "\b" * idx, str.join(""), "\b" * (str.size - idx - 1)
117 @history_idx = @history.size