fix: cap the repeat time when display usage (#2864)

This commit is contained in:
Yingjie He
2025-06-11 14:03:29 -07:00
committed by GitHub
parent 12d98507d5
commit 77c9ca2c28
2 changed files with 12 additions and 5 deletions

View File

@@ -621,12 +621,19 @@ pub fn display_greeting() {
pub fn display_context_usage(total_tokens: usize, context_limit: usize) {
use console::style;
// Calculate percentage used
let percentage = (total_tokens as f64 / context_limit as f64 * 100.0).round() as usize;
if context_limit == 0 {
println!("Context: Error - context limit is zero");
return;
}
// Create dot visualization
// Calculate percentage used with bounds checking
let percentage =
(((total_tokens as f64 / context_limit as f64) * 100.0).round() as usize).min(100);
// Create dot visualization with safety bounds
let dot_count = 10;
let filled_dots = ((percentage as f64 / 100.0) * dot_count as f64).round() as usize;
let filled_dots =
(((percentage as f64 / 100.0) * dot_count as f64).round() as usize).min(dot_count);
let empty_dots = dot_count - filled_dots;
let filled = "".repeat(filled_dots);