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<ctrl-c>" 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<enter><ctrl-c>" the command will be executed.

Clear the queue instead, including ctrl-c.
This matches other programs like gdb, Kakoune and possibly others.
This commit is contained in:
Johannes Altmanninger
2025-05-17 11:23:03 +02:00
parent 2071df126c
commit 3fcdbe1a19

View File

@@ -933,6 +933,7 @@ fn try_readch(&mut self, blocking: bool) -> Option<CharEvent> {
);
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);
}