summaryrefslogtreecommitdiffstats
path: root/src/bin/client/repl.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bin/client/repl.rs44
1 files changed, 29 insertions, 15 deletions
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 {
59 self.history_index = self.history.len(); 59 self.history_index = self.history.len();
60 redraw(""); 60 redraw("");
61 loop { 61 loop {
62 match read().unwrap() { 62 let event = read().unwrap();
63 Event::Key(key) => match key.code { 63 match event {
64 Event::Key(key) => {
65 // Only handle key press events, not release events
66 if key.kind == crossterm::event::KeyEventKind::Press {
67 match key.code {
64 KeyCode::Up => { 68 KeyCode::Up => {
65 if self.history_index > 0 { 69 if self.history_index > 0 {
66 self.history_index -= 1; 70 self.history_index -= 1;
@@ -331,26 +335,31 @@ impl ClientState {
331 KeyCode::Backspace => { 335 KeyCode::Backspace => {
332 if !current_input.is_empty() { 336 if !current_input.is_empty() {
333 current_input.pop(); 337 current_input.pop();
334 redraw(&current_input); 338 execute!(stdout(), MoveToColumn(2),
339 Clear(ClearType::UntilNewLine)).unwrap();
340 print!("{}", current_input);
341 stdout().flush().unwrap();
335 } 342 }
336 } 343 }
337 KeyCode::Char(c) => { 344 KeyCode::Char(c) => {
338 if key.modifiers.contains(KeyModifiers::CONTROL) && c == 'c' { 345 if key.modifiers.contains(KeyModifiers::CONTROL) && c == 'c' {
339 disable_raw_mode().unwrap();
340 execute!(stdout(), Show).unwrap(); 346 execute!(stdout(), Show).unwrap();
341 return; 347 return;
342 } else if c == '\t' { 348 } else if c == '\t' {
343 self.handle_tab_completion(&mut current_input); 349 self.handle_tab_completion(&mut current_input);
344 } else { 350 } else {
345 current_input.push(c); 351 current_input.push(c);
346 redraw(&current_input); 352 print!("{}", c);
353 stdout().flush().unwrap();
347 } 354 }
348 } 355 }
349 KeyCode::Tab => { 356 KeyCode::Tab => {
350 self.handle_tab_completion(&mut current_input); 357 self.handle_tab_completion(&mut current_input);
351 } 358 }
352 _ => {} 359 _ => {}
360 }
353 } 361 }
362 }
354 _ => {} 363 _ => {}
355 } 364 }
356 } 365 }
@@ -408,7 +417,7 @@ fn help() {
408 logout - logout from the server\r 417 logout - logout from the server\r
409 info - show login info\r 418 info - show login info\r
410 help - show this message\r 419 help - show this message\r
411 quit - quit the program\n"); 420 quit - quit the program");
412} 421}
413 422
414fn redraw(current_input: &str) { 423fn redraw(current_input: &str) {
@@ -420,7 +429,7 @@ fn redraw(current_input: &str) {
420 429
421fn read_line(prompt: &str) -> String { 430fn read_line(prompt: &str) -> String {
422 execute!(stdout(), Show).unwrap(); 431 execute!(stdout(), Show).unwrap();
423 print!("{}", prompt); 432 printsame!("{}", prompt);
424 stdout().flush().unwrap(); 433 stdout().flush().unwrap();
425 434
426 let mut input = String::new(); 435 let mut input = String::new();
@@ -428,7 +437,9 @@ fn read_line(prompt: &str) -> String {
428 437
429 loop { 438 loop {
430 match read().unwrap() { 439 match read().unwrap() {
431 Event::Key(key) => match key.code { 440 Event::Key(key) => {
441 if key.kind == crossterm::event::KeyEventKind::Press {
442 match key.code {
432 KeyCode::Enter => { 443 KeyCode::Enter => {
433 println!(); 444 println!();
434 break; 445 break;
@@ -448,7 +459,9 @@ fn read_line(prompt: &str) -> String {
448 stdout().flush().unwrap(); 459 stdout().flush().unwrap();
449 } 460 }
450 _ => {} 461 _ => {}
451 }, 462 }
463 }
464 }
452 _ => {} 465 _ => {}
453 } 466 }
454 } 467 }
@@ -461,12 +474,13 @@ fn read_password(prompt: &str) -> String {
461 stdout().flush().unwrap(); 474 stdout().flush().unwrap();
462 475
463 let mut input = String::new(); 476 let mut input = String::new();
464 let mut display = String::new();
465 let prompt_len = prompt.len(); 477 let prompt_len = prompt.len();
466 478
467 loop { 479 loop {
468 match read().unwrap() { 480 match read().unwrap() {
469 Event::Key(key) => match key.code { 481 Event::Key(key) => {
482 if key.kind == crossterm::event::KeyEventKind::Press {
483 match key.code {
470 KeyCode::Enter => { 484 KeyCode::Enter => {
471 println!(); 485 println!();
472 break; 486 break;
@@ -474,21 +488,21 @@ fn read_password(prompt: &str) -> String {
474 KeyCode::Backspace => { 488 KeyCode::Backspace => {
475 if !input.is_empty() { 489 if !input.is_empty() {
476 input.pop(); 490 input.pop();
477 display.pop();
478 // Move cursor back and clear from current position to end of line 491 // Move cursor back and clear from current position to end of line
479 execute!(stdout(), MoveToColumn((prompt_len + display.len() + 1) as u16), 492 execute!(stdout(), MoveToColumn((prompt_len + input.len() + 1) as u16),
480 Clear(ClearType::UntilNewLine)).unwrap(); 493 Clear(ClearType::UntilNewLine)).unwrap();
481 stdout().flush().unwrap(); 494 stdout().flush().unwrap();
482 } 495 }
483 } 496 }
484 KeyCode::Char(c) => { 497 KeyCode::Char(c) => {
485 input.push(c); 498 input.push(c);
486 display.push('*');
487 print!("*"); 499 print!("*");
488 stdout().flush().unwrap(); 500 stdout().flush().unwrap();
489 } 501 }
490 _ => {} 502 _ => {}
491 }, 503 }
504 }
505 }
492 _ => {} 506 _ => {}
493 } 507 }
494 } 508 }