Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions peri-tui/src/ui/message_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
};
use crate::app::tool_display::sanitize_display_text;

pub(crate) const CONTROL_B_BACKGROUND_HINT: &str = "(Ctrl+B to run in background)";
pub(crate) const CONTROL_B_BACKGROUND_HINT: &str = "(ctrl+b to run in background)";

/// 从 Bash 工具输出中解析 exit code。
///
Expand Down Expand Up @@ -944,10 +944,13 @@ pub fn render_view_model(
};
lines.push(Line::from(vec![
Span::styled(" ⎿ ", Style::default().fg(theme::DIM)),
Span::styled(elapsed_str, Style::default().fg(theme::MUTED)),
Span::styled(
format!("Running… {}", elapsed_str),
Style::default().fg(theme::MUTED),
),
]));
lines.push(Line::from(vec![
Span::styled(" ", Style::default().fg(theme::DIM)),
Span::styled(" ", Style::default().fg(theme::DIM)),
Span::styled(CONTROL_B_BACKGROUND_HINT, Style::default().fg(theme::MUTED)),
]));
}
Expand Down
33 changes: 32 additions & 1 deletion peri-tui/src/ui/message_render_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,46 @@
collapsed: true,
color: crate::ui::theme::SAGE,
diff_input: None,
started_at: Some(std::time::Instant::now() - std::time::Duration::from_secs(3)),
started_at: Some(std::time::Instant::now() - std::time::Duration::from_secs(39)),
content_hash: 0,
};
let lines = render_view_model(&vm, Some(1), 80, false, 0);
let rendered_lines: Vec<String> = lines
.iter()
.map(|line| {
line.spans
.iter()
.map(|span| span.content.as_ref())
.collect::<String>()
})
.collect();
let text = rendered_text(&lines);
assert!(
text.contains(crate::ui::message_render::CONTROL_B_BACKGROUND_HINT),
"运行超过 2 秒的 Bash ToolBlock 应显示 Ctrl+B 提示: {text:?}"
);
assert!(
rendered_lines[0].contains("● Bash(python wuhan_weather.py)"),
"Bash ToolBlock header 应保留运行中圆点和命令摘要: {rendered_lines:?}"
);
assert!(
rendered_lines
.iter()
.any(|line| line.contains("⎿ Running… (39s)")),
"Bash 运行状态应显示 Running… 和已运行时间: {rendered_lines:?}"
);
assert!(
rendered_lines
.iter()
.any(|line| line == " (ctrl+b to run in background)"),
"Ctrl+B 提示应作为缩进行显示,不应重复 ⎿: {rendered_lines:?}"
);
assert!(
!rendered_lines
.iter()
.any(|line| line.contains("⎿ (ctrl+b to run in background)")),
"Ctrl+B 提示行不应再带 ⎿ 前缀: {rendered_lines:?}"
);
}

#[test]
Expand Down
23 changes: 23 additions & 0 deletions peri-tui/src/ui/render_thread_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,4 +940,27 @@ fn test_refresh_running_bash_toolblock_adds_control_b_hint_after_threshold() {
.any(|span| span.content.as_ref().contains(CONTROL_B_BACKGROUND_HINT))),
"超过 2 秒后缓存中应出现 Ctrl+B 提示"
);
let rendered_lines: Vec<String> = cache
.read()
.lines
.iter()
.map(|line| {
line.spans
.iter()
.map(|span| span.content.as_ref())
.collect::<String>()
})
.collect();
assert!(
rendered_lines
.iter()
.any(|line| line.contains("⎿ Running…")),
"超过 2 秒后缓存中应出现 Running 状态行: {rendered_lines:?}"
);
assert!(
rendered_lines
.iter()
.any(|line| line == " (ctrl+b to run in background)"),
"Ctrl+B 提示应作为缩进行缓存: {rendered_lines:?}"
);
}
Loading