|
|
@ -160,6 +160,19 @@ impl Reader {
|
|
|
|
Ok(rec.into())
|
|
|
|
Ok(rec.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn log_recs(&mut self) {
|
|
|
|
|
|
|
|
debug!(" +---------------------+");
|
|
|
|
|
|
|
|
for i in 0..self.buf_len {
|
|
|
|
|
|
|
|
let rec = self.buf[i as usize];
|
|
|
|
|
|
|
|
let e: Event = rec.into();
|
|
|
|
|
|
|
|
match e {
|
|
|
|
|
|
|
|
Event::Key(k) => debug!(" | {} |", k),
|
|
|
|
|
|
|
|
_ => debug!(" | {:<14?} |", &e),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
debug!(" +---------------------+");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn next_rec(&mut self) -> Result<Console::INPUT_RECORD> {
|
|
|
|
fn next_rec(&mut self) -> Result<Console::INPUT_RECORD> {
|
|
|
|
if self.buf_idx as u32 >= self.buf_len {
|
|
|
|
if self.buf_idx as u32 >= self.buf_len {
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
@ -170,6 +183,7 @@ impl Reader {
|
|
|
|
))?;
|
|
|
|
))?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug!("• {}", self.buf_len);
|
|
|
|
debug!("• {}", self.buf_len);
|
|
|
|
|
|
|
|
self.log_recs();
|
|
|
|
self.buf_idx = 0;
|
|
|
|
self.buf_idx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -179,34 +193,91 @@ impl Reader {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn next_escape_sequence(&mut self) -> Result<Event> {
|
|
|
|
fn next_escape_sequence(&mut self) -> Result<Event> {
|
|
|
|
self.take_bracket()?;
|
|
|
|
|
|
|
|
match self.next_escape_char()? {
|
|
|
|
match self.next_escape_char()? {
|
|
|
|
'A' => Ok(Event::Up),
|
|
|
|
'[' => match self.next_escape_char()? {
|
|
|
|
'B' => Ok(Event::Down),
|
|
|
|
'A' => Ok(Event::Up),
|
|
|
|
'C' => Ok(Event::Right),
|
|
|
|
'B' => Ok(Event::Down),
|
|
|
|
'D' => Ok(Event::Left),
|
|
|
|
'C' => Ok(Event::Right),
|
|
|
|
'H' => Ok(Event::Home),
|
|
|
|
'D' => Ok(Event::Left),
|
|
|
|
'F' => Ok(Event::End),
|
|
|
|
'H' => Ok(Event::Home),
|
|
|
|
e => Err(Error::input_error(format!("unexpected escape char: {}", e)).into()),
|
|
|
|
'F' => Ok(Event::End),
|
|
|
|
}
|
|
|
|
'1' => match self.next_escape_char()? {
|
|
|
|
}
|
|
|
|
'3' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
';' => match self.next_escape_char()? {
|
|
|
|
fn take_bracket(&mut self) -> Result<()> {
|
|
|
|
'5' => match self.next_escape_char()? {
|
|
|
|
let rec = self.next_rec()?;
|
|
|
|
'u' => Ok(Event::Drop(String::from("13;5u"))),
|
|
|
|
if rec.EventType as u32 != Console::KEY_EVENT {
|
|
|
|
e => Err(Error::input_error(format!("[13;5 unexpected escape char: {}", e)).into()),
|
|
|
|
Err(Error::input_error("failed to read escape sequence: not a key event").into())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
e => Err(Error::input_error(format!("[13; unexpected escape char: {}", e)).into()),
|
|
|
|
unsafe {
|
|
|
|
}
|
|
|
|
let event = rec.Event.KeyEvent;
|
|
|
|
e => Err(Error::input_error(format!("[13 unexpected escape char: {}", e)).into()),
|
|
|
|
if event.wVirtualKeyCode == 0 && event.uChar.UnicodeChar == 91 {
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
'5' => match self.next_escape_char()? {
|
|
|
|
} else {
|
|
|
|
'~' => Ok(Event::Drop(String::from("[15~ - F5"))),
|
|
|
|
Err(Error::input_error("failed to read escape sequence: not a [").into())
|
|
|
|
e => Err(Error::input_error(format!("[15 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
'7' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[17~ - F6"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[17 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
'8' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[18~ - F7"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[18 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
'9' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[19~ - F8"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[19 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[1 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
'2' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'0' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[20~ - F9"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[20 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
'1' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[21~ - F10"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[20 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
'3' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[23~ - F11"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[23 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
'4' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'~' => Ok(Event::Drop(String::from("[24~ - F12"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[24 unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[2 unexpected escape char: {}", e)).into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("[ unexpected escape char: {}", e)).into()),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
'O' => match self.next_escape_char()? {
|
|
|
|
|
|
|
|
'P' => Ok(Event::Drop(String::from("OP - F1"))),
|
|
|
|
|
|
|
|
'Q' => Ok(Event::Drop(String::from("OQ - F2"))),
|
|
|
|
|
|
|
|
'R' => Ok(Event::Drop(String::from("OR - F3"))),
|
|
|
|
|
|
|
|
'S' => Ok(Event::Drop(String::from("OS - F4"))),
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("O unexpected escape char: {}", e)).into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e => Err(Error::input_error(format!("unexpected escape char: {}", e)).into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fn take_bracket(&mut self) -> Result<()> {
|
|
|
|
|
|
|
|
// let rec = self.next_rec()?;
|
|
|
|
|
|
|
|
// if rec.EventType as u32 != Console::KEY_EVENT {
|
|
|
|
|
|
|
|
// Err(Error::input_error("failed to read escape sequence: not a key event").into())
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// unsafe {
|
|
|
|
|
|
|
|
// let event = rec.Event.KeyEvent;
|
|
|
|
|
|
|
|
// if event.wVirtualKeyCode == 0 && event.uChar.UnicodeChar == 91 {
|
|
|
|
|
|
|
|
// Ok(())
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// Err(Error::input_error("failed to read escape sequence: not a [").into())
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
fn next_escape_char(&mut self) -> Result<char> {
|
|
|
|
fn next_escape_char(&mut self) -> Result<char> {
|
|
|
|
let rec = self.next_rec()?;
|
|
|
|
let rec = self.next_rec()?;
|
|
|
|
if rec.EventType as u32 != Console::KEY_EVENT {
|
|
|
|
if rec.EventType as u32 != Console::KEY_EVENT {
|
|
|
@ -240,6 +311,7 @@ pub enum Event {
|
|
|
|
Down,
|
|
|
|
Down,
|
|
|
|
Home,
|
|
|
|
Home,
|
|
|
|
End,
|
|
|
|
End,
|
|
|
|
|
|
|
|
Drop(String),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ALT_KEYS: u32 = 0x0002 | 0x0001;
|
|
|
|
const ALT_KEYS: u32 = 0x0002 | 0x0001;
|
|
|
|