diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-24 19:12:12 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-24 19:12:12 +0200 |
| commit | 119810728772084d3e24a8e50329f1b73b68a858 (patch) | |
| tree | fcbe2b17e1ddb8365340f0f20643324de346fde7 /src | |
| parent | Fix TUI: stable 7-line game render, no extra newlines, spin busy flag prevent... (diff) | |
| download | zagan-bet-119810728772084d3e24a8e50329f1b73b68a858.tar.gz zagan-bet-119810728772084d3e24a8e50329f1b73b68a858.zip | |
Fix TUI: render_lines 6 for correct MoveUp, drain buffered events before clearing spinning flag, clean redraw_game
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/client/games/slots.rs | 2 | ||||
| -rw-r--r-- | src/bin/client/repl.rs | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/bin/client/games/slots.rs b/src/bin/client/games/slots.rs index 76a5c4d..ff55274 100644 --- a/src/bin/client/games/slots.rs +++ b/src/bin/client/games/slots.rs | |||
| @@ -38,7 +38,7 @@ impl Game for SlotsGame { | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | fn render_lines(&self, _state: &GameState) -> usize { | 40 | fn render_lines(&self, _state: &GameState) -> usize { |
| 41 | 7 | 41 | 6 |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | fn get_help(&self) -> String { | 44 | fn get_help(&self) -> String { |
diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index b5707ad..a6f0331 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs | |||
| @@ -102,6 +102,11 @@ impl ClientState { | |||
| 102 | Err(e) => println!("\nError starting game: {:?}", e), | 102 | Err(e) => println!("\nError starting game: {:?}", e), |
| 103 | } | 103 | } |
| 104 | self.stream = Some(stream); | 104 | self.stream = Some(stream); |
| 105 | // Drain buffered key events BEFORE clearing spinning | ||
| 106 | // to prevent queued spins from triggering immediately | ||
| 107 | while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) { | ||
| 108 | let _ = crossterm::event::read(); | ||
| 109 | } | ||
| 105 | self.spinning = false; | 110 | self.spinning = false; |
| 106 | } | 111 | } |
| 107 | } | 112 | } |
| @@ -788,6 +793,8 @@ fn help() { | |||
| 788 | } | 793 | } |
| 789 | 794 | ||
| 790 | fn redraw_game(game_output: &str) { | 795 | fn redraw_game(game_output: &str) { |
| 796 | // After Enter, \r moves cursor to col 0 of the "> command" line. | ||
| 797 | // Clear that line and everything below, then draw game UI. | ||
| 791 | execute!( | 798 | execute!( |
| 792 | stdout(), | 799 | stdout(), |
| 793 | Clear(ClearType::CurrentLine), | 800 | Clear(ClearType::CurrentLine), |
| @@ -795,7 +802,7 @@ fn redraw_game(game_output: &str) { | |||
| 795 | MoveToColumn(0) | 802 | MoveToColumn(0) |
| 796 | ) | 803 | ) |
| 797 | .unwrap(); | 804 | .unwrap(); |
| 798 | print!("{}\r", game_output); | 805 | print!("{}", game_output); |
| 799 | stdout().flush().unwrap(); | 806 | stdout().flush().unwrap(); |
| 800 | } | 807 | } |
| 801 | 808 | ||
| @@ -811,7 +818,7 @@ fn redraw_game_lines(game_output: &str, lines: usize) { | |||
| 811 | MoveToColumn(0) | 818 | MoveToColumn(0) |
| 812 | ) | 819 | ) |
| 813 | .unwrap(); | 820 | .unwrap(); |
| 814 | print!("{}\r", game_output); | 821 | print!("{}", game_output); |
| 815 | stdout().flush().unwrap(); | 822 | stdout().flush().unwrap(); |
| 816 | } | 823 | } |
| 817 | 824 | ||
