Skip to content

Commit 307ad02

Browse files
Merge pull request #126 from unhappychoice/feat/color-coded-session-score
feat: Color-code session score display based on ranking tier
2 parents f64e2fa + 7237046 commit 307ad02

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/game/screens/result_screen.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::game::ascii_digits::get_digit_patterns;
22
use crate::game::ascii_rank_titles_generated::get_rank_title_display;
3-
use crate::scoring::{ScoringEngine, TypingMetrics};
3+
use crate::scoring::{RankingTitle, ScoringEngine, TypingMetrics};
44
use crate::sharing::{SharingPlatform, SharingService};
55
use crate::Result;
66
use crossterm::{
@@ -169,7 +169,12 @@ impl ResultScreen {
169169
} else if metrics.was_skipped {
170170
execute!(stdout, SetForegroundColor(Color::DarkGrey))?;
171171
} else {
172-
execute!(stdout, SetForegroundColor(Color::Green))?;
172+
execute!(
173+
stdout,
174+
SetForegroundColor(
175+
RankingTitle::for_score(metrics.challenge_score).terminal_color()
176+
)
177+
)?;
173178
}
174179
execute!(stdout, Print(line))?;
175180
execute!(stdout, ResetColor)?;
@@ -421,7 +426,9 @@ impl ResultScreen {
421426
execute!(
422427
stdout,
423428
SetAttribute(Attribute::Bold),
424-
SetForegroundColor(Color::Green)
429+
SetForegroundColor(
430+
RankingTitle::for_score(session_metrics.challenge_score).terminal_color()
431+
)
425432
)?;
426433
execute!(stdout, Print(line))?;
427434
execute!(stdout, ResetColor)?;

src/scoring/ranking_title.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ impl RankingTier {
2727
RankingTier::Legendary => "fire",
2828
}
2929
}
30+
31+
/// Get the terminal color for this tier
32+
pub fn terminal_color(&self) -> crossterm::style::Color {
33+
use crossterm::style::Color;
34+
match self {
35+
RankingTier::Beginner => Color::Cyan,
36+
RankingTier::Intermediate => Color::Blue,
37+
RankingTier::Advanced => Color::Green,
38+
RankingTier::Expert => Color::Yellow,
39+
RankingTier::Legendary => Color::Red,
40+
}
41+
}
3042
}
3143

3244
impl RankingTitle {
@@ -63,6 +75,11 @@ impl RankingTitle {
6375
self.tier.color_palette()
6476
}
6577

78+
/// Get the terminal color for this ranking title
79+
pub fn terminal_color(&self) -> crossterm::style::Color {
80+
self.tier.terminal_color()
81+
}
82+
6683
/// Get all ranking titles in order from lowest to highest score (matches engine.rs exactly)
6784
pub fn all_titles() -> Vec<RankingTitle> {
6885
vec![

0 commit comments

Comments
 (0)