From ef570e6ba8c3d6f5e90a07a26ef7385b0278198a Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 11 Mar 2026 21:04:08 +0100 Subject: stable and working, both platforms --- src/bin/client/repl.rs | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src/bin/client/repl.rs') diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index 4e787cb..a0e5b5e 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs @@ -59,8 +59,12 @@ impl ClientState { self.history_index = self.history.len(); redraw(""); loop { - match read().unwrap() { - Event::Key(key) => match key.code { + let event = read().unwrap(); + match event { + Event::Key(key) => { + // Only handle key press events, not release events + if key.kind == crossterm::event::KeyEventKind::Press { + match key.code { KeyCode::Up => { if self.history_index > 0 { self.history_index -= 1; @@ -331,26 +335,31 @@ impl ClientState { KeyCode::Backspace => { if !current_input.is_empty() { current_input.pop(); - redraw(¤t_input); + execute!(stdout(), MoveToColumn(2), + Clear(ClearType::UntilNewLine)).unwrap(); + print!("{}", current_input); + stdout().flush().unwrap(); } } KeyCode::Char(c) => { if key.modifiers.contains(KeyModifiers::CONTROL) && c == 'c' { - disable_raw_mode().unwrap(); execute!(stdout(), Show).unwrap(); return; } else if c == '\t' { self.handle_tab_completion(&mut current_input); } else { current_input.push(c); - redraw(¤t_input); + print!("{}", c); + stdout().flush().unwrap(); } } KeyCode::Tab => { self.handle_tab_completion(&mut current_input); } _ => {} + } } + } _ => {} } } @@ -408,7 +417,7 @@ fn help() { logout - logout from the server\r info - show login info\r help - show this message\r - quit - quit the program\n"); + quit - quit the program"); } fn redraw(current_input: &str) { @@ -420,7 +429,7 @@ fn redraw(current_input: &str) { fn read_line(prompt: &str) -> String { execute!(stdout(), Show).unwrap(); - print!("{}", prompt); + printsame!("{}", prompt); stdout().flush().unwrap(); let mut input = String::new(); @@ -428,7 +437,9 @@ fn read_line(prompt: &str) -> String { loop { match read().unwrap() { - Event::Key(key) => match key.code { + Event::Key(key) => { + if key.kind == crossterm::event::KeyEventKind::Press { + match key.code { KeyCode::Enter => { println!(); break; @@ -448,7 +459,9 @@ fn read_line(prompt: &str) -> String { stdout().flush().unwrap(); } _ => {} - }, + } + } + } _ => {} } } @@ -461,12 +474,13 @@ fn read_password(prompt: &str) -> String { stdout().flush().unwrap(); let mut input = String::new(); - let mut display = String::new(); let prompt_len = prompt.len(); loop { match read().unwrap() { - Event::Key(key) => match key.code { + Event::Key(key) => { + if key.kind == crossterm::event::KeyEventKind::Press { + match key.code { KeyCode::Enter => { println!(); break; @@ -474,21 +488,21 @@ fn read_password(prompt: &str) -> String { KeyCode::Backspace => { if !input.is_empty() { input.pop(); - display.pop(); // Move cursor back and clear from current position to end of line - execute!(stdout(), MoveToColumn((prompt_len + display.len() + 1) as u16), + execute!(stdout(), MoveToColumn((prompt_len + input.len() + 1) as u16), Clear(ClearType::UntilNewLine)).unwrap(); stdout().flush().unwrap(); } } KeyCode::Char(c) => { input.push(c); - display.push('*'); print!("*"); stdout().flush().unwrap(); } _ => {} - }, + } + } + } _ => {} } } -- cgit v1.2.3