diff --git a/src/widgets/git.rs b/src/widgets/git.rs index eec5e68..0f0579d 100644 --- a/src/widgets/git.rs +++ b/src/widgets/git.rs @@ -11,11 +11,11 @@ const DIRTY: (u8, u8, u8) = palette::YELLOW; const ADD: (u8, u8, u8) = palette::GREEN; const DEL: (u8, u8, u8) = palette::RED; -/// 如 `master ~3 +45 -12`;干净时只显示分支名;不在仓库时 `-`。 +/// 如 `master ~3 +45 -12`;干净时只显示分支名;不在仓库时返回空串(整段隐藏)。 pub fn render(status: &Status) -> String { match git::info(status.cwd.as_deref()) { Some(info) => format_info(&info), - None => "-".to_string(), + None => String::new(), } } diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 051f8fb..8000f29 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -31,5 +31,12 @@ pub fn render(status: &Status) -> String { speed::render(status), rate::render(status), ]; - parts.join(SEP) + // 无数据的组件返回空串:连同它的分隔符一起跳过, + // 避免开局出现一排没意义的占位(`| - | ↑ — ↓ — t/s | -`)。 + parts + .iter() + .filter(|p| !p.is_empty()) + .map(String::as_str) + .collect::>() + .join(SEP) } diff --git a/src/widgets/rate.rs b/src/widgets/rate.rs index fc86124..18d1155 100644 --- a/src/widgets/rate.rs +++ b/src/widgets/rate.rs @@ -12,10 +12,10 @@ const RED_AT: f64 = 80.0; /// 5h 窗口秒数,用于倒计时渐变。 const FIVE_HOUR_SECS: f64 = 5.0 * 3600.0; -/// 如 `10.0% / 40.0% 1h45min`;无数据时 `-`。 +/// 如 `10.0% / 40.0% 1h45min`;无数据时返回空串(整段隐藏)。 pub fn render(status: &Status) -> String { let Some(rl) = status.rate_limits.as_ref() else { - return "-".to_string(); + return String::new(); }; let five = rl.five_hour.as_ref().and_then(|p| p.used_percentage); diff --git a/src/widgets/speed.rs b/src/widgets/speed.rs index fee8142..ec4d837 100644 --- a/src/widgets/speed.rs +++ b/src/widgets/speed.rs @@ -10,9 +10,13 @@ const DOWN: &str = "↓"; /// 固定配色:柔青。 const COLOR: (u8, u8, u8) = palette::CYAN; -/// 读取转录、算速度并格式化,如 `↑2.7 ↓134.4 t/s`。 +/// 读取转录、算速度并格式化,如 `↑2.7 ↓134.4 t/s`;完全无数据时返回空串(整段隐藏)。 pub fn render(status: &Status) -> String { - display(&compute(status)) + let speed = compute(status); + if speed.input_per_sec.is_none() && speed.output_per_sec.is_none() { + return String::new(); + } + display(&speed) } /// 把速度格式化成 `↑输入 ↓输出 t/s` 并上色。供渲染与 `test token` 预览共用。