From 44d614378faebee49357831a2bc77ed6ece3a404 Mon Sep 17 00:00:00 2001 From: Georg Bauer Date: Tue, 28 Jul 2026 18:59:07 +0200 Subject: [PATCH] Group chat token counts by thousands --- src/app/view/chat.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/view/chat.rs b/src/app/view/chat.rs index c84ae89..7d50b76 100644 --- a/src/app/view/chat.rs +++ b/src/app/view/chat.rs @@ -427,9 +427,9 @@ fn generation_summary(stats: crate::app::generation::GenerationStats) -> Element text(format!( "{} · {} input · {} cached · {} output", format_duration(stats.duration_ms as f64 / 1_000.0), - stats.input_tokens, - stats.cached_tokens, - stats.output_tokens, + format_token_count(stats.input_tokens), + format_token_count(stats.cached_tokens), + format_token_count(stats.output_tokens), )) .size(11) .color(muted_text()), @@ -441,6 +441,18 @@ fn generation_summary(stats: crate::app::generation::GenerationStats) -> Element .into() } +fn format_token_count(value: u32) -> String { + let digits = value.to_string(); + let mut output = String::with_capacity(digits.len() + digits.len() / 3); + for (index, digit) in digits.chars().enumerate() { + if index > 0 && (digits.len() - index).is_multiple_of(3) { + output.push(','); + } + output.push(digit); + } + output +} + fn tool_cards(cards: Vec) -> Element<'static, Message> { let mut rows = column![].spacing(0); for (index, card) in cards.into_iter().enumerate() { @@ -517,3 +529,16 @@ fn tool_cards(cards: Vec) -> Element<'static, Message> { .style(preference_group_style) .into() } + +#[cfg(test)] +mod tests { + use super::format_token_count; + + #[test] + fn chat_divider_groups_token_counts_by_thousands() { + assert_eq!(format_token_count(0), "0"); + assert_eq!(format_token_count(999), "999"); + assert_eq!(format_token_count(1_000), "1,000"); + assert_eq!(format_token_count(12_345_678), "12,345,678"); + } +}