Files
claude-statusline/src/section/tools.rs
Taylor Eernisse b55d1aefd1 feat: complete Rust port of claude-statusline
Port the entire 2236-line bash statusline script to Rust.
Implements all 25 sections, 3-phase layout engine (render, priority
drop, flex/justify), file-based caching with flock, 9-level terminal
width detection, trend sparklines, and deep-merge JSON config.

Release binary: 864K with LTO. Render time: <1ms warm.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 14:21:57 -05:00

34 lines
800 B
Rust

use crate::color;
use crate::section::{RenderContext, SectionOutput};
pub fn render(ctx: &RenderContext) -> Option<SectionOutput> {
if !ctx.config.sections.tools.base.enabled {
return None;
}
let cost = ctx.input.cost.as_ref()?;
let count = cost.total_tool_uses.unwrap_or(0);
if count == 0 {
return None;
}
let last = if ctx.config.sections.tools.show_last_name {
cost.last_tool_name
.as_deref()
.map(|n| format!(" ({n})"))
.unwrap_or_default()
} else {
String::new()
};
let raw = format!("{count} tools{last}");
let ansi = if ctx.color_enabled {
format!("{}{raw}{}", color::DIM, color::RESET)
} else {
raw.clone()
};
Some(SectionOutput { raw, ansi })
}