From c64c695a88be23f00e89254f5080b905fe114019 Mon Sep 17 00:00:00 2001 From: Chris Gambrell Date: Mon, 27 Oct 2025 15:20:51 -0400 Subject: [PATCH 1/4] CTRL+Z then Enter will now close shell on Windows. --- vm/src/readline.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/vm/src/readline.rs b/vm/src/readline.rs index 839ac98003..91f875345d 100644 --- a/vm/src/readline.rs +++ b/vm/src/readline.rs @@ -88,6 +88,15 @@ mod rustyline_readline { ) .expect("failed to initialize line editor"); repl.set_helper(Some(helper)); + + #[cfg(windows)] + { + repl.bind_sequence( + KeyEvent::new('z', Modifiers::CTRL), + EventHandler::Simple(Cmd::Insert(1, "\u{001A}".into())), + ); + } + Self { repl } } @@ -115,7 +124,19 @@ mod rustyline_readline { use rustyline::error::ReadlineError; loop { break match self.repl.readline(prompt) { - Ok(line) => ReadlineResult::Line(line), + Ok(line) => { + // Check for CTRL + Z on Windows + #[cfg(windows)] + { + use std::io::IsTerminal; + + let trimmed = line.trim_end_matches(&['\r', '\n'][..]); + if trimmed == "\u{001A}" && io::stdin().is_terminal() { + return ReadlineResult::Eof; + } + } + ReadlineResult::Line(line) + } Err(ReadlineError::Interrupted) => ReadlineResult::Interrupt, Err(ReadlineError::Eof) => ReadlineResult::Eof, Err(ReadlineError::Io(e)) => ReadlineResult::Io(e), From 2b3ee6120b9282500be6a428bac9a0b4fe91d540 Mon Sep 17 00:00:00 2001 From: Chris Gambrell Date: Mon, 27 Oct 2025 15:22:47 -0400 Subject: [PATCH 2/4] Additional comment. --- vm/src/readline.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vm/src/readline.rs b/vm/src/readline.rs index 91f875345d..b99d15c569 100644 --- a/vm/src/readline.rs +++ b/vm/src/readline.rs @@ -88,7 +88,8 @@ mod rustyline_readline { ) .expect("failed to initialize line editor"); repl.set_helper(Some(helper)); - + + // Bind CTRL + Z to insert EOF character on Windows #[cfg(windows)] { repl.bind_sequence( From e6089ab9a113856fff103bc2c022e08a498b4480 Mon Sep 17 00:00:00 2001 From: Chris Gambrell Date: Mon, 27 Oct 2025 15:38:30 -0400 Subject: [PATCH 3/4] Use EOF const --- vm/src/readline.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vm/src/readline.rs b/vm/src/readline.rs index b99d15c569..28dfcc75b1 100644 --- a/vm/src/readline.rs +++ b/vm/src/readline.rs @@ -76,6 +76,8 @@ mod rustyline_readline { repl: rustyline::Editor, } + const EOF_CHAR: &str = "\u{001A}"; + impl Readline { pub fn new(helper: H) -> Self { use rustyline::*; @@ -88,13 +90,13 @@ mod rustyline_readline { ) .expect("failed to initialize line editor"); repl.set_helper(Some(helper)); - + // Bind CTRL + Z to insert EOF character on Windows #[cfg(windows)] { repl.bind_sequence( KeyEvent::new('z', Modifiers::CTRL), - EventHandler::Simple(Cmd::Insert(1, "\u{001A}".into())), + EventHandler::Simple(Cmd::Insert(1, EOF_CHAR.into())), ); } @@ -132,7 +134,7 @@ mod rustyline_readline { use std::io::IsTerminal; let trimmed = line.trim_end_matches(&['\r', '\n'][..]); - if trimmed == "\u{001A}" && io::stdin().is_terminal() { + if trimmed == EOF_CHAR && io::stdin().is_terminal() { return ReadlineResult::Eof; } } From 7cabf8ec29e7ceb40a142065d8355eb8f1451aaf Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Tue, 28 Oct 2025 09:45:36 +0900 Subject: [PATCH 4/4] Add cfg(windows) for EOF_CHAR --- vm/src/readline.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/src/readline.rs b/vm/src/readline.rs index 28dfcc75b1..77402dc683 100644 --- a/vm/src/readline.rs +++ b/vm/src/readline.rs @@ -76,6 +76,7 @@ mod rustyline_readline { repl: rustyline::Editor, } + #[cfg(windows)] const EOF_CHAR: &str = "\u{001A}"; impl Readline {