Add print_g3_progress/print_g3_status methods for consistent status messages

This commit is contained in:
Dhanji R. Prasanna
2026-01-16 20:28:24 +05:30
parent 95f89d3f8e
commit 0e33465342
7 changed files with 123 additions and 21 deletions

View File

@@ -338,16 +338,16 @@ async fn handle_command<W: UiWriter>(
Ok(true)
}
"/compact" => {
output.print("g3: compacting session ...");
output.print_g3_progress("compacting session");
match agent.force_compact().await {
Ok(true) => {
output.print("g3: compacting session ... done");
output.print_g3_status("compacting session", "done");
}
Ok(false) => {
output.print("g3: compacting session ... failed");
output.print_g3_status("compacting session", "failed");
}
Err(e) => {
output.print(&format!("g3: compacting session ... error: {}", e));
output.print_g3_status("compacting session", &format!("error: {}", e));
}
}
Ok(true)

View File

@@ -1,3 +1,5 @@
use crossterm::style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor};
/// Simple output helper for printing messages
#[derive(Clone)]
pub struct SimpleOutput;
@@ -14,6 +16,49 @@ impl SimpleOutput {
pub fn print_smart(&self, message: &str) {
println!("{}", message);
}
/// Print a g3 status message with colored tag and status
/// Format: "g3: <message> ... [status]"
/// - "g3:" is bold green
/// - "done" status is normal
/// - "failed" and "error" statuses are red
pub fn print_g3_status(&self, message: &str, status: &str) {
let status_colored = match status {
s if s.starts_with("error") || s == "failed" => {
format!(
"{}[{}]{}",
SetForegroundColor(Color::Red),
status,
ResetColor
)
}
_ => format!("[{}]", status),
};
println!(
"{}{}g3:{}{} {} ... {}",
SetAttribute(Attribute::Bold),
SetForegroundColor(Color::Green),
ResetColor,
SetAttribute(Attribute::Reset),
message,
status_colored
);
}
/// Print a g3 status message in progress (no status yet)
/// Format: "g3: <message> ..."
/// - "g3:" is bold green
pub fn print_g3_progress(&self, message: &str) {
println!(
"{}{}g3:{}{} {} ...",
SetAttribute(Attribute::Bold),
SetForegroundColor(Color::Green),
ResetColor,
SetAttribute(Attribute::Reset),
message
);
}
}
impl Default for SimpleOutput {

View File

@@ -211,6 +211,41 @@ impl UiWriter for ConsoleUiWriter {
println!("{}", message);
}
fn print_g3_progress(&self, message: &str) {
use crossterm::style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor};
println!(
"{}{}g3:{}{} {} ...",
SetAttribute(Attribute::Bold),
SetForegroundColor(Color::Green),
ResetColor,
SetAttribute(Attribute::Reset),
message
);
}
fn print_g3_status(&self, message: &str, status: &str) {
use crossterm::style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor};
let status_colored = if status.starts_with("error") || status == "failed" {
format!(
"{}[{}]{}",
SetForegroundColor(Color::Red),
status,
ResetColor
)
} else {
format!("[{}]", status)
};
println!(
"{}{}g3:{}{} {} ... {}",
SetAttribute(Attribute::Bold),
SetForegroundColor(Color::Green),
ResetColor,
SetAttribute(Attribute::Reset),
message,
status_colored
);
}
fn print_context_thinning(&self, message: &str) {
// Animated highlight for context thinning
// Use bright cyan/green with a quick flash animation