Infrastructure layer for the TUI visual overhaul. Introduces foundational
modules and capabilities that the section-level features build on:
colorgrad (0.7) dependency:
OKLab gradient interpolation for per-character color transitions in
sparklines and context bars. Adds ~100K to binary (929K -> 1.0M).
color.rs expansion:
- parse_hex(): #RRGGBB and #RGB -> (u8, u8, u8) conversion
- fg_rgb()/bg_rgb(): 24-bit true-color ANSI escape generation
- gradient_fg(): two-point interpolation via colorgrad
- make_gradient()/sample_fg(): multi-stop gradient construction and sampling
- resolve_color() now supports: hex (#FF6B35), bg:color, bg:#hex,
italic, underline, strikethrough, and palette refs (p:success)
- Named background constants (BG_RED through BG_WHITE)
transcript.rs (new module):
Parses Claude Code transcript JSONL files to derive tool use counts,
turn counts, and per-tool breakdowns. Claude Code doesn't include
total_tool_uses or total_turns in its JSON — we compute them by scanning
the transcript. Includes compact cache serialization format and
skip_lines support for /clear offset handling.
terminal.rs (new module):
Auto-detects the terminal's ANSI color palette for theme-aware tool
coloring. Priority chain: WezTerm config > Kitty config > Alacritty
config > OSC 4 escape sequence query. Parses Lua (WezTerm), key-value
(Kitty), and TOML/YAML (Alacritty) config formats. OSC 4 queries
use raw /dev/tty I/O with termios to avoid pipe interference. Includes
cache serialization helpers for 1-hour TTL caching.
input.rs updates:
- All structs now derive Serialize (for --dump-state diagnostics)
- New fields: transcript_path, session_id, cwd, vim.mode, agent.name,
exceeds_200k_tokens, cost.total_api_duration_ms
- CurrentUsage: added input_tokens and output_tokens fields
- #[serde(flatten)] extras on InputData and CostInfo for forward compat
cache.rs:
Added flush_prefix() for /clear detection — removes all cache entries
matching a key prefix (e.g., "trend_" to reset all sparkline history).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
88 lines
2.5 KiB
Rust
88 lines
2.5 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct InputData {
|
|
pub model: Option<ModelInfo>,
|
|
pub cost: Option<CostInfo>,
|
|
pub context_window: Option<ContextWindow>,
|
|
pub workspace: Option<Workspace>,
|
|
pub version: Option<String>,
|
|
pub output_style: Option<OutputStyle>,
|
|
pub transcript_path: Option<String>,
|
|
pub session_id: Option<String>,
|
|
pub cwd: Option<String>,
|
|
pub vim: Option<VimInfo>,
|
|
pub agent: Option<AgentInfo>,
|
|
pub exceeds_200k_tokens: Option<bool>,
|
|
#[serde(flatten)]
|
|
pub extra: std::collections::HashMap<String, serde_json::Value>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct VimInfo {
|
|
pub mode: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct AgentInfo {
|
|
pub name: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct ModelInfo {
|
|
pub id: Option<String>,
|
|
pub display_name: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct CostInfo {
|
|
pub total_cost_usd: Option<f64>,
|
|
pub total_duration_ms: Option<u64>,
|
|
pub total_api_duration_ms: Option<u64>,
|
|
pub total_lines_added: Option<u64>,
|
|
pub total_lines_removed: Option<u64>,
|
|
pub total_tool_uses: Option<u64>,
|
|
pub last_tool_name: Option<String>,
|
|
pub total_turns: Option<u64>,
|
|
/// Captures any fields we don't explicitly model (for debugging via --dump-state).
|
|
#[serde(flatten)]
|
|
pub extra: std::collections::HashMap<String, serde_json::Value>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct ContextWindow {
|
|
pub used_percentage: Option<f64>,
|
|
pub total_input_tokens: Option<u64>,
|
|
pub total_output_tokens: Option<u64>,
|
|
pub context_window_size: Option<u64>,
|
|
pub current_usage: Option<CurrentUsage>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct CurrentUsage {
|
|
pub input_tokens: Option<u64>,
|
|
pub output_tokens: Option<u64>,
|
|
pub cache_read_input_tokens: Option<u64>,
|
|
pub cache_creation_input_tokens: Option<u64>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct Workspace {
|
|
pub project_dir: Option<String>,
|
|
pub terminal_width: Option<u16>,
|
|
}
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
|
#[serde(default)]
|
|
pub struct OutputStyle {
|
|
pub name: Option<String>,
|
|
}
|