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>
This commit is contained in:
Taylor Eernisse
2026-02-06 14:21:57 -05:00
commit b55d1aefd1
65 changed files with 12439 additions and 0 deletions

47
src/metrics.rs Normal file
View File

@@ -0,0 +1,47 @@
use crate::input::InputData;
/// Derived metrics computed once from InputData, reused by all sections.
#[derive(Debug, Clone, Default)]
pub struct ComputedMetrics {
pub total_tokens: u64,
pub usage_pct: f64,
pub cost_velocity: Option<f64>,
pub token_velocity: Option<f64>,
pub cache_efficiency_pct: Option<f64>,
}
impl ComputedMetrics {
pub fn from_input(input: &InputData) -> Self {
let mut m = Self::default();
if let Some(ref cw) = input.context_window {
let input_tok = cw.total_input_tokens.unwrap_or(0);
let output_tok = cw.total_output_tokens.unwrap_or(0);
m.total_tokens = input_tok + output_tok;
m.usage_pct = cw.used_percentage.unwrap_or(0.0);
if let Some(ref usage) = cw.current_usage {
let cache_read = usage.cache_read_input_tokens.unwrap_or(0);
let cache_create = usage.cache_creation_input_tokens.unwrap_or(0);
let total_cache = cache_read + cache_create;
if total_cache > 0 {
m.cache_efficiency_pct = Some(cache_read as f64 / total_cache as f64 * 100.0);
}
}
}
if let Some(ref cost) = input.cost {
if let (Some(cost_usd), Some(duration_ms)) =
(cost.total_cost_usd, cost.total_duration_ms)
{
if duration_ms > 0 {
let minutes = duration_ms as f64 / 60_000.0;
m.cost_velocity = Some(cost_usd / minutes);
m.token_velocity = Some(m.total_tokens as f64 / minutes);
}
}
}
m
}
}