From 6ed4bf8c0bbe9e729e13637fad093fd6b1a3fd59 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Mon, 16 May 2022 15:32:17 +0200 Subject: [PATCH] fix(input): ANSI code sent to terminal on startup and resize * fix macos parsing issues * format * fix(ansiparser): validate first key on parse Co-authored-by: Aram Drevekenin --- zellij-client/src/stdin_ansi_parser.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/zellij-client/src/stdin_ansi_parser.rs b/zellij-client/src/stdin_ansi_parser.rs index efffffc8..31e6ccbb 100644 --- a/zellij-client/src/stdin_ansi_parser.rs +++ b/zellij-client/src/stdin_ansi_parser.rs @@ -17,7 +17,7 @@ impl StdinAnsiParser { } } pub fn increment_expected_ansi_instructions(&mut self, to: usize) { - self.expected_ansi_instructions = to; + self.expected_ansi_instructions += to; } pub fn decrement_expected_ansi_instructions(&mut self, by: usize) { self.expected_ansi_instructions = self.expected_ansi_instructions.saturating_sub(by); @@ -26,6 +26,16 @@ impl StdinAnsiParser { self.expected_ansi_instructions } pub fn parse(&mut self, key: Key, raw_bytes: Vec) -> Option { + if self.current_buffer.is_empty() + && (key != Key::Esc && key != Key::Alt(CharOrArrow::Char(']'))) + { + // the first key of a sequence is always Esc, but termwiz interprets esc + ] as Alt+] + self.current_buffer.push((key, raw_bytes)); + self.expected_ansi_instructions = 0; + return Some(AnsiStdinInstructionOrKeys::Keys( + self.current_buffer.drain(..).collect(), + )); + } if let Key::Char('t') = key { self.current_buffer.push((key, raw_bytes)); match AnsiStdinInstructionOrKeys::pixel_dimensions_from_keys(&self.current_buffer) { @@ -41,7 +51,7 @@ impl StdinAnsiParser { )) } } - } else if let Key::Alt(CharOrArrow::Char('\\')) = key { + } else if let Key::Alt(CharOrArrow::Char('\\')) | Key::Ctrl('g') = key { match AnsiStdinInstructionOrKeys::color_sequence_from_keys(&self.current_buffer) { Ok(color_instruction) => { self.decrement_expected_ansi_instructions(1); @@ -67,12 +77,6 @@ impl StdinAnsiParser { } } fn key_is_valid(&self, key: Key) -> bool { - if self.current_buffer.is_empty() - && (key != Key::Esc && key != Key::Alt(CharOrArrow::Char(']'))) - { - // the first key of a sequence is always Esc, but termwiz interprets esc + ] as Alt+] - return false; - } match key { Key::Esc => { // this is a UX improvement