From 119810728772084d3e24a8e50329f1b73b68a858 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 24 Aug 2026 19:12:12 +0200 Subject: Fix TUI: render_lines 6 for correct MoveUp, drain buffered events before clearing spinning flag, clean redraw_game --- src/bin/client/games/slots.rs | 2 +- src/bin/client/repl.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') 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 { } fn render_lines(&self, _state: &GameState) -> usize { - 7 + 6 } 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 { Err(e) => println!("\nError starting game: {:?}", e), } self.stream = Some(stream); + // Drain buffered key events BEFORE clearing spinning + // to prevent queued spins from triggering immediately + while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) { + let _ = crossterm::event::read(); + } self.spinning = false; } } @@ -788,6 +793,8 @@ fn help() { } fn redraw_game(game_output: &str) { + // After Enter, \r moves cursor to col 0 of the "> command" line. + // Clear that line and everything below, then draw game UI. execute!( stdout(), Clear(ClearType::CurrentLine), @@ -795,7 +802,7 @@ fn redraw_game(game_output: &str) { MoveToColumn(0) ) .unwrap(); - print!("{}\r", game_output); + print!("{}", game_output); stdout().flush().unwrap(); } @@ -811,7 +818,7 @@ fn redraw_game_lines(game_output: &str, lines: usize) { MoveToColumn(0) ) .unwrap(); - print!("{}\r", game_output); + print!("{}", game_output); stdout().flush().unwrap(); } -- cgit v1.2.3