diff --git a/Cargo.toml b/Cargo.toml index 0c6c5e48f..e6e6c72d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,6 @@ features = [ "keysyms", ] version = "0.2.0" + +[features] +debug-escape-sequences = ["term/debug-escape-sequences"] diff --git a/term/Cargo.toml b/term/Cargo.toml index 19136b674..4ba51d3c0 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -10,3 +10,6 @@ unicode-segmentation = "1.2.0" unicode-width = "0.1.4" vte = "0.3.2" +[features] +# When enabled, print the results of parsing the input stream to stdout +debug-escape-sequences = [] diff --git a/term/src/debug.rs b/term/src/debug.rs index f557e3e89..5f449473f 100644 --- a/term/src/debug.rs +++ b/term/src/debug.rs @@ -1,3 +1,5 @@ macro_rules! debug { - ($($arg:tt)*) => (if cfg!(debug_assertions) { println!($($arg)*) }) + ($($arg:tt)*) => (if cfg!(feature="debug-escape-sequences") { + println!($($arg)*) + }) } diff --git a/term/src/lib.rs b/term/src/lib.rs index 495425c36..bdd05ccb6 100644 --- a/term/src/lib.rs +++ b/term/src/lib.rs @@ -772,6 +772,7 @@ impl Terminal { impl vte::Perform for TerminalState { /// Draw a character to the screen fn print(&mut self, c: char) { + debug!("print {:x} {}", c as u32, c); if self.wrap_next { // TODO: remember that this was a wrapped line in the attributes? self.new_line(true); @@ -793,14 +794,14 @@ impl vte::Perform for TerminalState { } fn execute(&mut self, byte: u8) { + debug!("execute {:02x}", byte); match byte { b'\n' | 0x0b /* VT */ | 0x0c /* FF */ => { self.new_line(true /* TODO: depend on terminal mode */) } - b'\r' => { + b'\r' => /* CR */ { let row = self.cursor_y; - self.screen_mut().dirty_line(row); - self.cursor_x = 0; + self.set_cursor_pos(0, row); } 0x08 /* BS */ => { self.delta_cursor_pos(-1, 0); @@ -964,6 +965,13 @@ impl vte::Perform for TerminalState { } fn esc_dispatch(&mut self, params: &[i64], intermediates: &[u8], _ignore: bool, byte: u8) { + debug!( + "ESC params={:?}, intermediates={:?} b={:02x} {}", + params, + intermediates, + byte, + byte as char + ); // Sequences from both of these sections show up in this handler: // https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-C1-_8-Bit_-Control-Characters // https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Controls-beginning-with-ESC