From 11eb01e04ddb32b9d88d1251d023935f6224f121 Mon Sep 17 00:00:00 2001 From: Dhanji Prasanna Date: Fri, 31 Oct 2025 14:28:35 +1100 Subject: [PATCH] add back progress bar to cli --- crates/g3-cli/src/lib.rs | 29 ++++++++++++++++++++++++++--- crates/g3-cli/src/tui.rs | 20 +++++++++++--------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/crates/g3-cli/src/lib.rs b/crates/g3-cli/src/lib.rs index 56c1cf9..4426f75 100644 --- a/crates/g3-cli/src/lib.rs +++ b/crates/g3-cli/src/lib.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use crossterm::style::{Color, SetForegroundColor, ResetColor}; use std::time::{Duration, Instant}; #[derive(Debug, Clone)] @@ -1479,10 +1480,32 @@ fn handle_execution_error(e: &anyhow::Error, input: &str, output: &SimpleOutput, } } -fn display_context_progress(agent: &Agent, output: &SimpleOutput) { +fn display_context_progress(agent: &Agent, _output: &SimpleOutput) { let context = agent.get_context_window(); - output.print(&format!("Context: {}/{} tokens ({:.1}%)", - context.used_tokens, context.total_tokens, context.percentage_used())); + let percentage = context.percentage_used(); + + // Create 10 dots representing context fullness + let total_dots: usize = 10; + let filled_dots = ((percentage / 100.0) * total_dots as f32).round() as usize; + let empty_dots = total_dots.saturating_sub(filled_dots); + + let filled_str = "●".repeat(filled_dots); + let empty_str = "○".repeat(empty_dots); + + // Determine color based on percentage + let color = if percentage < 40.0 { + Color::Green + } else if percentage < 60.0 { + Color::Yellow + } else if percentage < 80.0 { + Color::Rgb { r: 255, g: 165, b: 0 } // Orange + } else { + Color::Red + }; + + // Print with colored dots (using print! directly to handle color codes) + print!("Context: {}{}{}{} {:.0}% ({}/{} tokens)\n", + SetForegroundColor(color), filled_str, empty_str, ResetColor, percentage, context.used_tokens, context.total_tokens); } /// Set up the workspace directory for autonomous mode diff --git a/crates/g3-cli/src/tui.rs b/crates/g3-cli/src/tui.rs index 452db5c..95e2996 100644 --- a/crates/g3-cli/src/tui.rs +++ b/crates/g3-cli/src/tui.rs @@ -71,18 +71,20 @@ impl SimpleOutput { } pub fn print_context(&self, used: u32, total: u32, percentage: f32) { - let bar_width: usize = 10; - let filled_width = ((percentage / 100.0) * bar_width as f32) as usize; - let empty_width = bar_width.saturating_sub(filled_width); + let total_dots = 10; + let filled_dots = ((percentage / 100.0) * total_dots as f32) as usize; + let empty_dots = total_dots.saturating_sub(filled_dots); - let filled_chars = "●".repeat(filled_width); - let empty_chars = "○".repeat(empty_width); + let filled_str = "●".repeat(filled_dots); + let empty_str = "○".repeat(empty_dots); // Determine color based on percentage - let color = if percentage < 60.0 { + let color = if percentage < 40.0 { crossterm::style::Color::Green - } else if percentage < 80.0 { + } else if percentage < 60.0 { crossterm::style::Color::Yellow + } else if percentage < 80.0 { + crossterm::style::Color::Rgb { r: 255, g: 165, b: 0 } // Orange } else { crossterm::style::Color::Red }; @@ -90,9 +92,9 @@ impl SimpleOutput { // Print with colored progress bar print!("Context: "); print!("{}", SetForegroundColor(color)); - print!("{}{}", filled_chars, empty_chars); + print!("{}{}", filled_str, empty_str); print!("{}", ResetColor); - println!(" {:.1}% | {}/{} tokens", percentage, used, total); + println!(" {:.0}% ({}/{} tokens)", percentage, used, total); } pub fn print_context_thinning(&self, message: &str) {