Simplify surrogate pair handling on windows
diff --git a/src/tty/windows.rs b/src/tty/windows.rs
index 103ec44..bfd3be9 100644
--- a/src/tty/windows.rs
+++ b/src/tty/windows.rs
@@ -90,7 +90,6 @@
/// Console input reader
pub struct ConsoleRawReader {
handle: HANDLE,
- buf: [u16; 2],
}
impl ConsoleRawReader {
@@ -98,7 +97,6 @@
let handle = try!(get_std_handle(STDIN_FILENO));
Ok(ConsoleRawReader {
handle,
- buf: [0; 2],
})
}
}
@@ -113,7 +111,7 @@
let mut rec: wincon::INPUT_RECORD = unsafe { mem::zeroed() };
let mut count = 0;
- let mut surrogate = false;
+ let mut surrogate = 0;
loop {
// TODO GetNumberOfConsoleInputEvents
check!(consoleapi::ReadConsoleInputW(
@@ -210,18 +208,14 @@
return Ok(KeyPress::Esc);
} else {
if utf16 >= 0xD800 && utf16 < 0xDC00 {
- surrogate = true;
- self.buf[0] = utf16;
+ surrogate = utf16;
continue;
}
- let buf = if surrogate {
- self.buf[1] = utf16;
- &self.buf[..]
+ let orc = if surrogate == 0 {
+ decode_utf16(Some(utf16)).next()
} else {
- self.buf[0] = utf16;
- &self.buf[..1]
+ decode_utf16([surrogate, utf16].iter().cloned()).next()
};
- let orc = decode_utf16(buf.iter().cloned()).next();
if orc.is_none() {
return Err(error::ReadlineError::Eof);
}