feat: hide segments with no data instead of showing placeholders
- git/speed/rate return an empty string when they have no real data - render() skips empty parts along with their separators, so an absent segment leaves no dangling `|` - avoids the startup row of placeholders (`| - | ↑ — ↓ — t/s | -`), collapsing the line to only the segments that actually have data
This commit is contained in:
+2
-2
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -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::<Vec<_>>()
|
||||
.join(SEP)
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
@@ -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` 预览共用。
|
||||
|
||||
Reference in New Issue
Block a user