From 263a4e8a2e835d9bd5a6410b724ff05aa04de643 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 6 Jun 2016 17:41:03 -0700 Subject: [PATCH] Fix escape bytes as input bug in ANSI parser There were several unrecognized escape codes that have arguments which were being interpretted as input. Naturally, this caused state to be corrupt. The escape codes are now handled by throwing away the bytes. Consider this a TODO for later. --- src/ansi.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ansi.rs b/src/ansi.rs index cd61c6d5..e3d0f7bf 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -421,6 +421,9 @@ impl Parser { }, State::Csi => { self.csi(handler, c); + }, + State::EscapeOther => { + self.other(handler, c); } } } @@ -431,6 +434,18 @@ impl Parser { handler.input(c); } + fn other(&mut self, handler: &mut H, c: char) + where H: Handler + { + if c == 0x07 as char || c == 0x18 as char || c == 0x1a as char || + c == 0x1b as char || is_control_c1(c) + { + self.state = State::Base; + } + + // TODO actually use these bytes. For now, we just throw them away. + } + /// Handle character following an ESC /// /// TODO Handle `ST`, `'#'`, `'P'`, `'_'`, `'^'`, `']'`, `'k'`, @@ -458,6 +473,9 @@ impl Parser { 'c' => sequence_complete!(reset_state), '7' => sequence_complete!(save_cursor_position), '8' => sequence_complete!(restore_cursor_position), + 'P' | '_' | '^' | ']' | 'k' | '(' => { + self.state = State::EscapeOther; + }, _ => { self.state = State::Base; err_println!("Unknown ESC 0x{:02x} {:?}", c as usize, c); @@ -1042,6 +1060,9 @@ enum State { /// Parsing a CSI escape, Csi, + + /// Parsing non csi escape + EscapeOther, } impl Default for State {