From 43c44ae6fe7dbfcf6af3e5e53c29f65bbf94c9c2 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 16:43:04 +0200 Subject: shell: ^C cancels the line / aborts streams, ^D = EOF → poweroff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ps2: Ctrl+C and Ctrl+D are now KeyEvents (ctrl modifier + c/d map); other Ctrl+key combos are swallowed - shell read_line: ^C clears the line and echoes '^C' (bash-style), ^D on an empty line echoes '^D' and shuts down (EOF), ^D with text on the line is ignored - cat/hexdump stream incrementally (was: build whole string then print) and check for ^C between chunks, so a running dump can be aborted - verified in QEMU: line cancel, standalone interrupt, ^C aborts an infinite 'cat /dev/zero' stream, ^D powers off --- rsnix/src/ps2.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'rsnix/src/ps2.rs') diff --git a/rsnix/src/ps2.rs b/rsnix/src/ps2.rs index 477d146..1b10b3b 100644 --- a/rsnix/src/ps2.rs +++ b/rsnix/src/ps2.rs @@ -22,6 +22,8 @@ pub enum KeyEvent { Backspace, Tab, Escape, + CtrlC, + CtrlD, ArrowUp, ArrowDown, ArrowLeft, @@ -304,6 +306,15 @@ fn process_byte(byte: u8) -> Option { ch.to_ascii_uppercase() }; } + // Ctrl+letter — the shell uses ^C (interrupt) and ^D (EOF). + let ctrl = state.modifiers & (MOD_LCTRL | MOD_RCTRL) != 0; + if ctrl { + return match ch.to_ascii_lowercase() { + b'c' => Some(KeyEvent::CtrlC), + b'd' => Some(KeyEvent::CtrlD), + _ => None, // swallow other Ctrl+key combinations + }; + } if ch != 0 { Some(KeyEvent::Char(ch as char)) } else { -- cgit v1.2.3