diff --git a/src/app.rs b/src/app.rs index cdee587..9911b9c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -127,29 +127,29 @@ fn render_start_screen(state: &mut StartMenuState, area: Rect, buf: &mut Buffer) } fn handle_crossterm_events(app_state: &mut AppState) -> color_eyre::Result<()> { - if let Event::Key(key) = event::read()? { - if key.kind == KeyEventKind::Press { - match key.code { - // global exit via Ctrl+C - KeyCode::Char('c') | KeyCode::Char('C') - if key.modifiers == KeyModifiers::CONTROL => - { - *app_state = AppState::Exit; - } + if let Event::Key(key) = event::read()? + && key.kind == KeyEventKind::Press + { + match key.code { + // global exit via Ctrl+C + KeyCode::Char('c') | KeyCode::Char('C') + if key.modifiers == KeyModifiers::CONTROL => + { + *app_state = AppState::Exit; + } - // state-specific input handling - _ => { - *app_state = match std::mem::replace(app_state, AppState::Exit) { - AppState::Start(mut menu) => { - handle_start_input(&mut menu, key) - .unwrap_or(AppState::Start(menu)) - } - AppState::Playing(mut game) => { - game.handle_input(key); - AppState::Playing(game) - } - AppState::Exit => AppState::Exit, + // state-specific input handling + _ => { + *app_state = match std::mem::replace(app_state, AppState::Exit) { + AppState::Start(mut menu) => { + handle_start_input(&mut menu, key) + .unwrap_or(AppState::Start(menu)) } + AppState::Playing(mut game) => { + game.handle_input(key); + AppState::Playing(game) + } + AppState::Exit => AppState::Exit, } } } diff --git a/src/binary_numbers.rs b/src/binary_numbers.rs index 98857c4..a3cbb58 100644 --- a/src/binary_numbers.rs +++ b/src/binary_numbers.rs @@ -168,7 +168,7 @@ impl WidgetRef for BinaryNumbersPuzzle { Block::bordered().border_type(border_type).fg(border_color).render(area, buf); let suggestion_str = format!("{suggestion}"); - Paragraph::new(format!("{}", suggestion_str)) + Paragraph::new(suggestion_str.to_string()) .white() .when(show_correct_number && is_correct_number, |p| p.light_green().underlined()) .alignment(Center) @@ -241,7 +241,7 @@ impl WidgetRef for BinaryNumbersPuzzle { Block::bordered().dark_gray().render(result_area, buf); - let instruction_spans: Vec = vec![ + let instruction_spans: Vec = [ hotkey_span("Left Right", "select "), hotkey_span("Enter", "confirm "), hotkey_span("S", "skip "), @@ -293,7 +293,7 @@ impl MainScreenWidget for BinaryNumbersGame { self.refresh_stats_snapshot(); } - fn handle_input(&mut self, input: KeyEvent) -> () { self.handle_game_input(input); } + fn handle_input(&mut self, input: KeyEvent) { self.handle_game_input(input); } fn is_exit_intended(&self) -> bool { self.exit_intended } } @@ -632,8 +632,7 @@ impl Widget for &mut BinaryNumbersGame { // Simple ASCII gauge renderer to avoid variable glyph heights from Unicode block elements fn render_ascii_gauge(area: Rect, buf: &mut Buffer, ratio: f64, color: Color) { - let clamped = if ratio < 0.0 { 0.0 } else if ratio > 1.0 { 1.0 } else { ratio }; - let fill_width = ((area.width as f64) * clamped).round().min(area.width as f64) as u16; + let fill_width = ((area.width as f64) * ratio.clamp(0.0, 1.0)).round().min(area.width as f64) as u16; if area.height == 0 { return; } for x in 0..area.width { let filled = x < fill_width; @@ -664,10 +663,11 @@ impl HighScores { let mut contents = String::new(); if file.read_to_string(&mut contents).is_ok() { for line in contents.lines() { - if let Some((k,v)) = line.split_once('=') { - if let (Ok(bits), Ok(score)) = (k.trim().parse::(), v.trim().parse::()) { - hs.scores.insert(bits, score); - } + if let Some((k,v)) = line.split_once('=') + && let Ok(bits) = k.trim().parse::() + && let Ok(score) = v.trim().parse::() + { + hs.scores.insert(bits, score); } } } diff --git a/src/utils.rs b/src/utils.rs index f83daec..f0d0b04 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -89,8 +89,8 @@ impl Widget for AsciiArtWidget { pub fn center(area: Rect, horizontal: Constraint) -> Rect { let [area] = Layout::horizontal([horizontal]).flex(Flex::Center).areas(area); - let area = vertically_center(area); - area + + vertically_center(area) } pub fn vertically_center(area: Rect) -> Rect {