78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/rcommand/io_methods.rb', line 78
def readline
if @command_line.prompt != nil && @command_line.io_write != nil
@command_line.io_write.print(@command_line.prompt)
end
command = ""
char = nil
loop do
char = self.readchar()
next if char.nil?
next if char == 0
if char != 9
@tab_count = 0
end
if char == 3
raise Interrupt
elsif char == 10
@command_line.io_write.print("\n")
self << command
break
elsif char == 9
@tab_count += 1
replacement = nil
if @tab_count == 1
unless @command_line.procs[:single_tab].nil?
replacement = @command_line.procs[:single_tab].call(command)
end
elsif @tab_count > 1
unless @command_line.procs[:double_tab].nil?
replacement = @command_line.procs[:double_tab].call(command)
end
end
if replacement != nil && replacement.size > command.size
@command_line.io_write.print(
8.chr * command.size +
" " * command.size +
8.chr * command.size)
@command_line.io_write.print(replacement)
command = replacement
end
elsif char == 8 || char == 127
if command.size > 0
command = command[0..-2]
@command_line.io_write.print(8.chr + " " + 8.chr)
end
else
command << char.chr
replacement = nil
if command.index("\e[A") != nil
command.gsub!("\e[A", "")
unless @command_line.procs[:key_up].nil?
replacement = @command_line.procs[:key_up].call(command)
end
elsif command.index("\e[B") != nil
command.gsub!("\e[B", "")
unless @command_line.procs[:key_down].nil?
replacement = @command_line.procs[:key_down].call(command)
end
elsif command.index("\e[C") != nil
command.gsub!("\e[C", "")
unless @command_line.procs[:key_right].nil?
replacement = @command_line.procs[:key_right].call(command)
end
elsif command.index("\e[D") != nil
command.gsub!("\e[D", "")
unless @command_line.procs[:key_left].nil?
replacement = @command_line.procs[:key_left].call(command)
end
else
if (char == "["[0] && command[-2] != "\e"[0]) ||
(char != "\e"[0] && char != "["[0])
@command_line.io_write.print(char.chr)
end
end
if replacement != nil
@command_line.io_write.print(
8.chr * command.size +
" " * command.size +
8.chr * command.size)
@command_line.io_write.print(replacement)
command = replacement
end
end
end
return command + "\n"
end
|