diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-24 18:54:23 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-24 18:54:23 +0200 |
| commit | 7474924a7cfdfc3d03795157f5098aaa524dac71 (patch) | |
| tree | d9cdafb59db4e9adda34be6edcbbce68316156e0 /src/bin/client/repl.rs | |
| parent | v0.2.1: fix connect error overwriting prompt in raw mode (diff) | |
| download | zagan-bet-7474924a7cfdfc3d03795157f5098aaa524dac71.tar.gz zagan-bet-7474924a7cfdfc3d03795157f5098aaa524dac71.zip | |
Fix TUI: stable 7-line game render, no extra newlines, spin busy flag prevents queueing
Diffstat (limited to 'src/bin/client/repl.rs')
| -rw-r--r-- | src/bin/client/repl.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index d10edba..b5707ad 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs | |||
| @@ -28,6 +28,7 @@ pub struct ClientState { | |||
| 28 | pub game_manager: GameManager, | 28 | pub game_manager: GameManager, |
| 29 | cleanup_done: Arc<Mutex<bool>>, | 29 | cleanup_done: Arc<Mutex<bool>>, |
| 30 | in_game_mode: bool, | 30 | in_game_mode: bool, |
| 31 | spinning: bool, | ||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | impl ClientState { | 34 | impl ClientState { |
| @@ -54,6 +55,7 @@ impl ClientState { | |||
| 54 | game_manager: GameManager::new(), | 55 | game_manager: GameManager::new(), |
| 55 | cleanup_done: Arc::new(Mutex::new(false)), | 56 | cleanup_done: Arc::new(Mutex::new(false)), |
| 56 | in_game_mode: false, | 57 | in_game_mode: false, |
| 58 | spinning: false, | ||
| 57 | } | 59 | } |
| 58 | } | 60 | } |
| 59 | 61 | ||
| @@ -78,11 +80,15 @@ impl ClientState { | |||
| 78 | return true; | 80 | return true; |
| 79 | } | 81 | } |
| 80 | KeyCode::Char(' ') => { | 82 | KeyCode::Char(' ') => { |
| 83 | if self.spinning { | ||
| 84 | return true; // Discard keypress while busy | ||
| 85 | } | ||
| 81 | let can_spin = self.game_manager.get_current_state() | 86 | let can_spin = self.game_manager.get_current_state() |
| 82 | .map(|s| s.phase == GamePhase::WaitingToStart || s.phase == GamePhase::Finished) | 87 | .map(|s| s.phase == GamePhase::WaitingToStart || s.phase == GamePhase::Finished) |
| 83 | .unwrap_or(false); | 88 | .unwrap_or(false); |
| 84 | if can_spin { | 89 | if can_spin { |
| 85 | if let Some(mut stream) = self.stream.take() { | 90 | if let Some(mut stream) = self.stream.take() { |
| 91 | self.spinning = true; | ||
| 86 | match self.game_manager.start_game(&mut stream) { | 92 | match self.game_manager.start_game(&mut stream) { |
| 87 | Ok(()) => { | 93 | Ok(()) => { |
| 88 | let response = self.read_server_response(&mut stream); | 94 | let response = self.read_server_response(&mut stream); |
| @@ -96,6 +102,7 @@ impl ClientState { | |||
| 96 | Err(e) => println!("\nError starting game: {:?}", e), | 102 | Err(e) => println!("\nError starting game: {:?}", e), |
| 97 | } | 103 | } |
| 98 | self.stream = Some(stream); | 104 | self.stream = Some(stream); |
| 105 | self.spinning = false; | ||
| 99 | } | 106 | } |
| 100 | } | 107 | } |
| 101 | return true; | 108 | return true; |
| @@ -788,7 +795,7 @@ fn redraw_game(game_output: &str) { | |||
| 788 | MoveToColumn(0) | 795 | MoveToColumn(0) |
| 789 | ) | 796 | ) |
| 790 | .unwrap(); | 797 | .unwrap(); |
| 791 | println!("{}", game_output); | 798 | print!("{}\r", game_output); |
| 792 | stdout().flush().unwrap(); | 799 | stdout().flush().unwrap(); |
| 793 | } | 800 | } |
| 794 | 801 | ||
| @@ -804,7 +811,7 @@ fn redraw_game_lines(game_output: &str, lines: usize) { | |||
| 804 | MoveToColumn(0) | 811 | MoveToColumn(0) |
| 805 | ) | 812 | ) |
| 806 | .unwrap(); | 813 | .unwrap(); |
| 807 | println!("{}", game_output); | 814 | print!("{}\r", game_output); |
| 808 | stdout().flush().unwrap(); | 815 | stdout().flush().unwrap(); |
| 809 | } | 816 | } |
| 810 | 817 | ||
