From 2915d826f744612e0d975282f5bddf13270b9f3f Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 28 Oct 2026 23:19:52 +0100 Subject: v1.1.0: highlight winning symbols on the slots board --- src/bin/client/repl.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/bin') diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index 033fb1a..58cb541 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs @@ -240,8 +240,12 @@ impl ClientState { .map(|line| { if line.starts_with("===") { line.as_str().bold().cyan().to_string() - } else if line.contains("JACKPOT") || line.contains("Two of a kind") { + } else if line.contains('{') { + style_winning_cells(line) + } else if line.contains("WIN!") || line.starts_with("Won ") { line.as_str().bold().green().to_string() + } else if line.starts_with("Winning lines:") { + line.as_str().yellow().to_string() } else if line.starts_with("ERROR:") { line.as_str().red().to_string() } else { @@ -436,6 +440,31 @@ impl ClientState { } } +fn style_winning_cells(line: &str) -> String { + let chars: Vec = line.chars().collect(); + let mut out = String::new(); + let mut index = 0; + + while index < chars.len() { + if chars[index] == '{' { + let start = index; + while index < chars.len() && chars[index] != '}' { + index += 1; + } + if index < chars.len() { + index += 1; + } + let cell: String = chars[start..index].iter().collect(); + out.push_str(&cell.as_str().bold().yellow().to_string()); + } else { + out.push(chars[index]); + index += 1; + } + } + + out +} + fn map_key(key: crossterm::event::KeyEvent) -> Option { if key.modifiers.contains(KeyModifiers::CONTROL) { match key.code { -- cgit v1.2.3