From 3fcdbe1a1931647ba76b86bac144b613ae8c5811 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 17 May 2025 11:23:03 +0200 Subject: [PATCH] Discard input queue when ctrl-c is pressed while waiting for query response On startup, we block until the terminal responds to our primary device attribute query. As an escape hatch, ctrl-c makes us stop waiting. No keys are discarded; even ctrl-c is still enqueued. Usually this isn't noticed because typing "echo" will insert a "echo" only to immediately clear it. The double interpretation of ctrl-c seems odd. Additionally, the queuing seems unsafe considering that when typing something like "echo hello" the command will be executed. Clear the queue instead, including ctrl-c. This matches other programs like gdb, Kakoune and possibly others. --- src/input_common.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/input_common.rs b/src/input_common.rs index 170dc69c9..0329f8fc6 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -933,6 +933,7 @@ fn try_readch(&mut self, blocking: bool) -> Option { ); let ok = stop_query(self.blocking_query()); assert!(ok); + self.get_input_data_mut().queue.clear(); } continue; } @@ -1637,7 +1638,7 @@ fn enqueue_interrupt_key(&mut self) { reader, "Received interrupt, giving up on waiting for terminal response" ); - self.push_back(interrupt_evt); + self.get_input_data_mut().queue.clear(); } else { self.push_front(interrupt_evt); }