150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/reline/windows.rb', line 150
def self.getc
num_of_events = 0.chr * 8
while @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) != 0 and num_of_events.unpack('L').first > 0
input_record = 0.chr * 18
read_event = 0.chr * 4
if @@ReadConsoleInput.(@@hConsoleInputHandle, input_record, 1, read_event) != 0
event = input_record[0, 2].unpack('s*').first
if event == WINDOW_BUFFER_SIZE_EVENT
@@winch_handler.()
end
end
end
unless @@output_buf.empty?
return @@output_buf.shift
end
input = getwch
meta = (@@GetKeyState.call(VK_LMENU) & 0x80) != 0
control = (@@GetKeyState.call(VK_CONTROL) & 0x80) != 0
shift = (@@GetKeyState.call(VK_SHIFT) & 0x80) != 0
force_enter = !input.instance_of?(Array) && (control or shift) && input == 0x0D
if force_enter
@@output_buf.push("\e".ord)
@@output_buf.push(input)
else
case input
when 0x00
meta = false
@@output_buf.push(input)
input = getwch
@@output_buf.push(*input)
when 0xE0
@@output_buf.push(input)
input = getwch
@@output_buf.push(*input)
when 0x03
@@output_buf.push(input)
else
@@output_buf.push(input)
end
end
if meta
"\e".ord
else
@@output_buf.shift
end
end
|