From 828470137cb4e806c31a26fa741d5d67c64f98c2 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 28 Oct 2026 22:31:18 +0100 Subject: v0.2.4: fix command UX, completion wrapping and auth prompt cancellation --- src/bin/client/repl.rs | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/bin') diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index e9d32a0..3fa49b8 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs @@ -290,11 +290,11 @@ impl ClientState { fn do_login(&mut self) { loop { - let username = read_line("Username: "); + let username = read_line("Username: ", &self.cleanup_done); if username.is_empty() { break; } - let password = read_password("Password: "); + let password = read_password("Password: ", &self.cleanup_done); if password.is_empty() { break; } @@ -329,11 +329,11 @@ impl ClientState { } fn do_register(&mut self) { - let username = read_line("Username: "); + let username = read_line("Username: ", &self.cleanup_done); if username.is_empty() { return; } - let password = read_password("Password: "); + let password = read_password("Password: ", &self.cleanup_done); if password.is_empty() { return; } @@ -357,11 +357,11 @@ impl ClientState { println!("No host connected. Use 'connect :' first."); return; } - let username = read_line("Username: "); + let username = read_line("Username: ", &self.cleanup_done); if username.is_empty() { return; } - let password = read_password("Password: "); + let password = read_password("Password: ", &self.cleanup_done); if password.is_empty() { return; } @@ -419,7 +419,7 @@ fn restore_terminal(cleanup_done: &Arc>) { } } -fn read_line(prompt: &str) -> String { +fn read_line(prompt: &str, cleanup_done: &Arc>) -> String { execute!(stdout(), Show).unwrap(); printsame!("{}", prompt); stdout().flush().unwrap(); @@ -451,6 +451,20 @@ fn read_line(prompt: &str) -> String { stdout().flush().unwrap(); } } + KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => { + println!(); + restore_terminal(cleanup_done); + std::process::exit(0); + } + KeyCode::Char('d') if key.modifiers.contains(KeyModifiers::CONTROL) => { + println!(); + restore_terminal(cleanup_done); + std::process::exit(0); + } + KeyCode::Esc => { + println!(); + return String::new(); + } KeyCode::Char(c) => { input.push(c); print!("{}", c); @@ -466,7 +480,7 @@ fn read_line(prompt: &str) -> String { input.trim().to_string() } -fn read_password(prompt: &str) -> String { +fn read_password(prompt: &str, cleanup_done: &Arc>) -> String { execute!(stdout(), Show).unwrap(); print!("{}", prompt); stdout().flush().unwrap(); @@ -498,6 +512,20 @@ fn read_password(prompt: &str) -> String { stdout().flush().unwrap(); } } + KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => { + println!(); + restore_terminal(cleanup_done); + std::process::exit(0); + } + KeyCode::Char('d') if key.modifiers.contains(KeyModifiers::CONTROL) => { + println!(); + restore_terminal(cleanup_done); + std::process::exit(0); + } + KeyCode::Esc => { + println!(); + return String::new(); + } KeyCode::Char(c) => { input.push(c); print!("*"); -- cgit v1.2.3