//! 思考 + 模型,如 `H opus-4.8`,等级按等级配色、模型名柔蓝。 use crate::color; use crate::status::Status; /// 固定配色:柔蓝。 const COLOR: (u8, u8, u8) = (130, 170, 230); /// 如 `H opus-4.8`;思考缺失时只剩 `opus-4.8`;模型缺失时 `-`。 pub fn render(status: &Status) -> String { let name = status .model .as_ref() .and_then(|m| m.display_name()) .unwrap_or("-"); let level = status .effort .as_ref() .and_then(|e| e.level.as_deref()) .unwrap_or(""); combined(name, level) } /// 把思考等级与模型名拼成 `H opus-4.8` 并上色: /// 等级按等级配色在前,模型名柔蓝在后。供渲染与 `test` 预览共用。 pub fn combined(name: &str, level: &str) -> String { let (r, g, b) = COLOR; let model = color::fg(&name_format(name), r, g, b); let think = thinking_format(level); if think == "-" { return model; } let (r, g, b) = thinking_color(level); format!("{} {model}", color::fg(think, r, g, b)) } /// 模型名规范化:去 ` (...)` 后缀 → 小写 → 空格转 `-`,如 `Opus 4.8 (1M context)` → `opus-4.8`。 fn name_format(name: &str) -> String { let stripped = name.split(" (").next().unwrap_or(name).trim(); stripped.to_lowercase().replace(' ', "-") } /// 思考等级简写:low→L, medium→M, high→H, xhigh→XH;缺失/未知 `-`。 fn thinking_format(level: &str) -> &'static str { match level { "low" => "L", "medium" => "M", "high" => "H", "xhigh" => "XH", _ => "-", } } /// 思考等级配色:越高越「热」。L 绿 → M 黄 → H 橙 → XH 红。 fn thinking_color(level: &str) -> (u8, u8, u8) { match level { "low" => (120, 200, 140), // 柔绿 "medium" => (220, 210, 110), // 柔黄 "high" => (235, 165, 95), // 柔橙 "xhigh" => (228, 105, 105), // 柔红 _ => (150, 150, 150), // 灰(兜底,正常走不到) } }