diff --git a/src/preview.rs b/src/preview.rs index 37bc501..ba9b7db 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -73,7 +73,9 @@ fn model() { ("medium", "medium"), ("high", "high"), ("xhigh", "xhigh"), - ("缺失/未知", ""), + ("max", "max"), + ("未知", "xxhigh thinking"), + ("缺失", ""), ] { println!(" {} {}", pad(label, 10), widgets::model::combined("Opus 4.8 (1M context)", level)); } diff --git a/src/widgets/model.rs b/src/widgets/model.rs index b182e89..9ea47b2 100644 --- a/src/widgets/model.rs +++ b/src/widgets/model.rs @@ -6,7 +6,7 @@ use crate::status::Status; /// 固定配色:柔蓝。 const COLOR: (u8, u8, u8) = palette::BLUE; -/// 如 `H opus-4.8`;思考缺失时只剩 `opus-4.8`;模型缺失时 `-`。 +/// 如 `H opus-4.8`;思考缺失时等级位显示 `-`;模型缺失时模型名 `-`。 pub fn render(status: &Status) -> String { let name = status .model @@ -28,11 +28,8 @@ pub fn combined(name: &str, level: &str) -> String { 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)) + format!("{} {model}", color::fg(&think, r, g, b)) } /// 模型名规范化:去 ` (...)` 后缀 → 小写 → 空格转 `-`,如 `Opus 4.8 (1M context)` → `opus-4.8`。 @@ -41,25 +38,29 @@ fn name_format(name: &str) -> String { stripped.to_lowercase().replace(' ', "-") } -/// 思考等级简写:low→L, medium→M, high→H, xhigh→XH;缺失/未知 `-`。 -fn thinking_format(level: &str) -> &'static str { +/// 思考等级简写:low→L, medium→M, high→H, xhigh→XH, max→MAX。 +/// 没给等级(空串)显示 `-`;其它未知等级一律原样显示(大小写不动), +/// 免得没见过的等级被悄悄吞掉或被改了样子。 +fn thinking_format(level: &str) -> String { match level { - "low" => "L", - "medium" => "M", - "high" => "H", - "xhigh" => "XH", - _ => "-", + "" => "-".into(), + "low" => "L".into(), + "medium" => "M".into(), + "high" => "H".into(), + "xhigh" => "XH".into(), + "max" => "MAX".into(), + other => other.to_string(), } } -/// 思考等级配色:越高越「热」。L 绿 → M 黄 → H 橙 → XH 红。 +/// 思考等级配色:越高越「热」。L 绿 → M 黄 → H 橙 → XH/MAX 红;未知等级与缺失(`-`)用灰。 fn thinking_color(level: &str) -> (u8, u8, u8) { match level { "low" => palette::GREEN, "medium" => palette::YELLOW, "high" => palette::ORANGE, - "xhigh" => palette::RED, - _ => palette::GRAY, // 兜底,正常走不到 + "xhigh" | "max" => palette::RED, + _ => palette::GRAY, } } @@ -75,20 +76,39 @@ mod tests { } #[test] - fn thinking_format_known_and_unknown() { + fn thinking_format_known_levels() { assert_eq!(thinking_format("low"), "L"); assert_eq!(thinking_format("medium"), "M"); assert_eq!(thinking_format("high"), "H"); assert_eq!(thinking_format("xhigh"), "XH"); - assert_eq!(thinking_format("bogus"), "-"); + assert_eq!(thinking_format("max"), "MAX"); + } + + #[test] + fn thinking_format_unknown_shown_verbatim() { + // 未知等级要原样显示,大小写不改。 + assert_eq!(thinking_format("xxhigh thinking"), "xxhigh thinking"); + assert_eq!(thinking_format("Ultra"), "Ultra"); + } + + #[test] + fn thinking_format_empty_is_dash() { assert_eq!(thinking_format(""), "-"); } #[test] - fn combined_drops_thinking_when_level_unknown() { - // 等级未知时只剩模型名,前面不该挂等级。 - let only_model = combined("Sonnet 4.6", ""); - assert!(only_model.contains("sonnet-4.6")); - assert!(!only_model.contains('H')); + fn combined_shows_dash_when_level_empty() { + // 等级缺失时用 `-` 占位,仍然显示。 + let s = combined("Sonnet 4.6", ""); + assert!(s.contains("sonnet-4.6")); + assert!(s.contains('-')); + } + + #[test] + fn combined_shows_unknown_level_verbatim() { + // 未知等级(如 deepseek 的 xxhigh thinking)原样显示出来。 + let s = combined("Opus 4.8", "xxhigh thinking"); + assert!(s.contains("opus-4.8")); + assert!(s.contains("xxhigh thinking")); } }