Treat Japanese IME on/off code correctly
This commit is contained in:
parent
b0d885da76
commit
85dc89c907
@ -66,23 +66,27 @@ class Reline::Windows
|
|||||||
@@hConsoleInputHandle = @@GetStdHandle.call(STD_INPUT_HANDLE)
|
@@hConsoleInputHandle = @@GetStdHandle.call(STD_INPUT_HANDLE)
|
||||||
@@GetNumberOfConsoleInputEvents = Win32API.new('kernel32', 'GetNumberOfConsoleInputEvents', ['L', 'P'], 'L')
|
@@GetNumberOfConsoleInputEvents = Win32API.new('kernel32', 'GetNumberOfConsoleInputEvents', ['L', 'P'], 'L')
|
||||||
@@ReadConsoleInput = Win32API.new('kernel32', 'ReadConsoleInput', ['L', 'P', 'L', 'P'], 'L')
|
@@ReadConsoleInput = Win32API.new('kernel32', 'ReadConsoleInput', ['L', 'P', 'L', 'P'], 'L')
|
||||||
@@buf = []
|
@@input_buf = []
|
||||||
|
@@output_buf = []
|
||||||
|
|
||||||
def self.getwch
|
def self.getwch
|
||||||
|
unless @@input_buf.empty?
|
||||||
|
return @@input_buf.shift
|
||||||
|
end
|
||||||
while @@kbhit.call == 0
|
while @@kbhit.call == 0
|
||||||
sleep(0.001)
|
sleep(0.001)
|
||||||
end
|
end
|
||||||
result = []
|
|
||||||
until @@kbhit.call == 0
|
until @@kbhit.call == 0
|
||||||
ret = @@getwch.call
|
ret = @@getwch.call
|
||||||
begin
|
begin
|
||||||
result.concat(ret.chr(Encoding::UTF_8).encode(Encoding.default_external).bytes)
|
bytes = ret.chr(Encoding::UTF_8).encode(Encoding.default_external).bytes
|
||||||
|
@@input_buf.push(*bytes)
|
||||||
rescue Encoding::UndefinedConversionError
|
rescue Encoding::UndefinedConversionError
|
||||||
result << ret
|
@@input_buf << ret
|
||||||
result << @@getwch.call if ret == 224
|
@@input_buf << @@getwch.call if ret == 224
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
result
|
@@input_buf.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.getc
|
def self.getc
|
||||||
@ -97,44 +101,42 @@ class Reline::Windows
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
unless @@buf.empty?
|
unless @@output_buf.empty?
|
||||||
return @@buf.shift
|
return @@output_buf.shift
|
||||||
end
|
end
|
||||||
input = getwch
|
input = getwch
|
||||||
alt = (@@GetKeyState.call(VK_MENU) & 0x80) != 0
|
alt = (@@GetKeyState.call(VK_MENU) & 0x80) != 0
|
||||||
shift_enter = (@@GetKeyState.call(VK_SHIFT) & 0x80) != 0 && input.first == 0x0D
|
shift_enter = !input.instance_of?(Array) && (@@GetKeyState.call(VK_SHIFT) & 0x80) != 0 && input == 0x0D
|
||||||
if shift_enter
|
if shift_enter
|
||||||
# It's treated as Meta+Enter on Windows
|
# It's treated as Meta+Enter on Windows
|
||||||
@@buf.concat(["\e".ord])
|
@@output_buf.push("\e".ord)
|
||||||
@@buf.concat(input)
|
@@output_buf.push(input)
|
||||||
elsif input.size > 1
|
else
|
||||||
@@buf.concat(input)
|
case input
|
||||||
else # single byte
|
|
||||||
case input[0]
|
|
||||||
when 0x00
|
when 0x00
|
||||||
getwch
|
getwch
|
||||||
alt = false
|
alt = false
|
||||||
input = getwch
|
input = getwch
|
||||||
@@buf.concat(input)
|
@@output_buf.push(*input)
|
||||||
when 0xE0
|
when 0xE0
|
||||||
@@buf.concat(input)
|
@@output_buf.push(input)
|
||||||
input = getwch
|
input = getwch
|
||||||
@@buf.concat(input)
|
@@output_buf.push(*input)
|
||||||
when 0x03
|
when 0x03
|
||||||
@@buf.concat(input)
|
@@output_buf.push(input)
|
||||||
else
|
else
|
||||||
@@buf.concat(input)
|
@@output_buf.push(input)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if alt
|
if alt
|
||||||
"\e".ord
|
"\e".ord
|
||||||
else
|
else
|
||||||
@@buf.shift
|
@@output_buf.shift
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ungetc(c)
|
def self.ungetc(c)
|
||||||
@@buf.unshift(c)
|
@@output_buf.unshift(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_screen_size
|
def self.get_screen_size
|
||||||
|
Loading…
x
Reference in New Issue
Block a user