From 810e212b4b255914cfa73e85b52ec23db281c0e3 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 23:06:22 +0100 Subject: v3.1.0: warn on shrink, but let a live round finish --- src/client/core.rs | 22 ++++++++++++++++++++++ src/client/ui.rs | 10 ++++++++++ 2 files changed, 32 insertions(+) (limited to 'src/client') diff --git a/src/client/core.rs b/src/client/core.rs index 8411d47..95fa050 100644 --- a/src/client/core.rs +++ b/src/client/core.rs @@ -138,6 +138,28 @@ impl ClientCore { self.game.is_in_game() } + /// True while a round is running and leaving would forfeit a reserved bet. + /// The terminal may shrink during one of these without interrupting it. + pub fn is_live_game(&self) -> bool { + match self + .game + .get_current_state() + .map(|state| state.game_type.as_str()) + { + Some("blackjack") => self + .game + .blackjack_state() + .is_some_and(|hand| hand.phase == "player"), + Some("crash") => self.crash_started.is_some(), + _ => false, + } + } + + /// Redraw the current board, for terminal resizes. + pub fn refresh_board(&self) -> Vec { + self.board_effects() + } + pub fn prompt_effect(&self) -> Option { if self.is_in_game() { return None; diff --git a/src/client/ui.rs b/src/client/ui.rs index 6161166..ca001c2 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -261,6 +261,16 @@ pub fn terminal_too_small(columns: u16, rows: u16) -> Option { )) } +/// One-line warning for a terminal that shrank while the client is running. +pub fn terminal_size_warning(columns: u16, rows: u16) -> Option { + if columns >= MIN_COLUMNS && rows >= MIN_ROWS { + return None; + } + Some(format!( + "WARNING: terminal is {columns}x{rows}; zagan.bet needs at least {MIN_COLUMNS}x{MIN_ROWS}. Resize to fit." + )) +} + /// Render remembered hosts. /// /// Two addresses that present the same certificate key are the same server, so -- cgit v1.2.3