Skip to content

Commit 6439449

Browse files
committed
Repair interleaved renderer and regression-test hunks
1 parent 4f20f2b commit 6439449

2 files changed

Lines changed: 75 additions & 75 deletions

File tree

‎crates/jcode-tui/src/tui/ui_messages.rs‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,16 +2793,6 @@ pub(crate) fn render_background_task_message(
27932793
if is_swarm && !parsed.status.starts_with('✗') {
27942794
return render_compact_swarm_background_completion(&parsed, width);
27952795
}
2796-
if parsed.status.starts_with('✗') {
2797-
let muted = Style::default().fg(dim_color());
2798-
let failure = Style::default().fg(rgb(220, 100, 100));
2799-
let block_width = if centered {
2800-
super::centered_content_block_width(width, 96)
2801-
} else {
2802-
width as usize
2803-
};
2804-
let row_width = block_width.saturating_sub(1);
2805-
let timing = msg
28062796
if parsed.status.starts_with('✓') {
28072797
let muted = Style::default().fg(dim_color());
28082798
let block_width = if centered {
@@ -2835,6 +2825,16 @@ pub(crate) fn render_background_task_message(
28352825
}
28362826
return lines;
28372827
}
2828+
if parsed.status.starts_with('✗') {
2829+
let muted = Style::default().fg(dim_color());
2830+
let failure = Style::default().fg(rgb(220, 100, 100));
2831+
let block_width = if centered {
2832+
super::centered_content_block_width(width, 96)
2833+
} else {
2834+
width as usize
2835+
};
2836+
let row_width = block_width.saturating_sub(1);
2837+
let timing = msg
28382838
.content
28392839
.lines()
28402840
.find_map(|line| {
@@ -4115,6 +4115,18 @@ fn inline_diff_header(
41154115
}
41164116
let mut header = Line::from(header);
41174117
if let Some(path) = file_path {
4118+
let path_width = width.saturating_sub(header.width().saturating_add(3));
4119+
if path_width > 0 {
4120+
header.spans.push(Span::styled(
4121+
format!(" · {}", tools_ui::truncate_path_display(path, path_width)),
4122+
dim,
4123+
));
4124+
}
4125+
}
4126+
super::truncate_line_with_ellipsis_to_width(&header, width)
4127+
.alignment(ratatui::layout::Alignment::Left)
4128+
}
4129+
41184130
/// Keep expanded source lines inside their frame. Wrap the styled source, not
41194131
/// the gutter, so continuation rows cannot masquerade as another changed line.
41204132
fn expanded_diff_row(
@@ -4188,18 +4200,6 @@ fn expanded_diff_row(
41884200
rows
41894201
}
41904202

4191-
let path_width = width.saturating_sub(header.width().saturating_add(3));
4192-
if path_width > 0 {
4193-
header.spans.push(Span::styled(
4194-
format!(" · {}", tools_ui::truncate_path_display(path, path_width)),
4195-
dim,
4196-
));
4197-
}
4198-
}
4199-
super::truncate_line_with_ellipsis_to_width(&header, width)
4200-
.alignment(ratatui::layout::Alignment::Left)
4201-
}
4202-
42034203
fn render_tool_failure_reason(content: &str, width: usize, indent: usize) -> Line<'static> {
42044204
let clean = strip_ansi_escape_sequences(content);
42054205
let summary = tools_ui::parse_tool_failure(&clean)
@@ -4732,11 +4732,6 @@ pub(crate) fn render_tool_message(
47324732
});
47334733
const MAX_DIFF_LINES: usize = MAX_INLINE_DIFF_LINES;
47344734
let total_changes = change_lines.len();
4735-
let number_width = change_lines
4736-
.iter()
4737-
.map(|line| line.prefix.trim().trim_end_matches(['+', '-']).len())
4738-
.max()
4739-
.unwrap_or(0);
47404735
let additions = change_lines
47414736
.iter()
47424737
.filter(|line| line.kind == DiffLineKind::Add)
@@ -4762,15 +4757,6 @@ pub(crate) fn render_tool_message(
47624757
|line: &ParsedDiffLine| line.file_path.clone().or_else(|| file_path_for_ext.clone());
47634758
let first_file_path = display_lines.first().and_then(|line| diff_file_path(line));
47644759
lines.push(inline_diff_header(
4765-
if full_inline {
4766-
let file_ext = current_file_path
4767-
.as_deref()
4768-
.and_then(|p| std::path::Path::new(p).extension())
4769-
.and_then(|e| e.to_str());
4770-
lines.extend(expanded_diff_row(line, file_ext, number_width, row_width));
4771-
continue;
4772-
}
4773-
47744760
"╭─",
47754761
Some((additions, deletions)),
47764762
first_file_path.as_deref(),
@@ -4779,6 +4765,11 @@ pub(crate) fn render_tool_message(
47794765

47804766
let mut shown_truncation = false;
47814767
let mut previous_file_path = first_file_path;
4768+
let number_width = change_lines
4769+
.iter()
4770+
.map(|line| line.prefix.trim().trim_end_matches(['+', '-']).len())
4771+
.max()
4772+
.unwrap_or(0);
47824773

47834774
for (i, line) in display_lines.iter().enumerate() {
47844775
if truncated && !shown_truncation && i >= half_point {
@@ -4804,6 +4795,15 @@ pub(crate) fn render_tool_message(
48044795
}
48054796
previous_file_path = current_file_path.clone();
48064797

4798+
if full_inline {
4799+
let file_ext = current_file_path
4800+
.as_deref()
4801+
.and_then(|p| std::path::Path::new(p).extension())
4802+
.and_then(|e| e.to_str());
4803+
lines.extend(expanded_diff_row(line, file_ext, number_width, row_width));
4804+
continue;
4805+
}
4806+
48074807
let base_color = if line.kind == DiffLineKind::Add {
48084808
diff_add_color()
48094809
} else {

‎crates/jcode-tui/src/tui/ui_messages/tests.rs‎

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -995,34 +995,13 @@ fn render_background_task_success_hides_ansi_preview_without_changing_raw() {
995995
"**Background task** `bg123` · `bash` · ✓ completed · 0.1s · exit 0\n\n```text\n\u{1b}[32m✓\u{1b}[39m passes \u{1b}[2m12ms\u{1b}[22m\n```\n\n_Full output:_ `bg action=\"output\" task_id=\"bg123\"`",
996996
);
997997

998+
let raw = msg.content.clone();
998999
let plain = render_background_task_message(&msg, 80, crate::config::DiffDisplayMode::Off)
9991000
.iter()
10001001
.map(extract_line_text)
10011002
.collect::<Vec<_>>()
10021003
.join("\n");
10031004

1004-
assert!(
1005-
plain.contains("✓ passes 12ms"),
1006-
"rendered preview:\n{plain}"
1007-
);
1008-
assert!(!plain.contains('\u{1b}'));
1009-
assert!(!plain.contains("[32m"));
1010-
assert!(!plain.contains("[2m"));
1011-
}
1012-
1013-
#[test]
1014-
fn render_system_message_strips_ansi_from_existing_inline_command_preview() {
1015-
let msg = DisplayMessage::system(
1016-
"Shell command · ✓ exit 0 · 12ms\n\n cargo test\n\n \u{1b}[32m✓\u{1b}[39m passes \u{1b}[2m12ms\u{1b}[22m",
1017-
);
1018-
1019-
let plain = render_system_message(&msg, 80, crate::config::DiffDisplayMode::Off)
1020-
.iter()
1021-
let raw = msg.content.clone();
1022-
.map(extract_line_text)
1023-
.collect::<Vec<_>>()
1024-
.join("\n");
1025-
10261005
assert!(plain.contains("✓ bash · took 0.1s"), "{plain}");
10271006
assert!(!plain.contains("passes"));
10281007
assert_eq!(msg.content, raw);
@@ -1031,8 +1010,6 @@ fn render_system_message_strips_ansi_from_existing_inline_command_preview() {
10311010
assert!(!plain.contains("[2m"));
10321011
}
10331012

1034-
#[test]
1035-
fn render_background_task_message_uses_swarm_flavor_for_swarm_tool() {
10361013
#[test]
10371014
fn render_background_task_success_fits_unicode_and_narrow_widths() {
10381015
let raw = "**Background task** `bg-unicode` · `验证界面 e\u{301} 🦀 long background intent` (`bash`) · ✓ completed · 12.3s · exit 0\n\n```text\nlarge output must stay hidden\n```\n\n_Full output:_ `bg action=\"output\" task_id=\"bg-unicode\"`";
@@ -1060,6 +1037,29 @@ fn render_background_task_success_fits_unicode_and_narrow_widths() {
10601037
assert_eq!(msg.content, raw);
10611038
}
10621039

1040+
#[test]
1041+
fn render_system_message_strips_ansi_from_existing_inline_command_preview() {
1042+
let msg = DisplayMessage::system(
1043+
"Shell command · ✓ exit 0 · 12ms\n\n cargo test\n\n \u{1b}[32m✓\u{1b}[39m passes \u{1b}[2m12ms\u{1b}[22m",
1044+
);
1045+
1046+
let plain = render_system_message(&msg, 80, crate::config::DiffDisplayMode::Off)
1047+
.iter()
1048+
.map(extract_line_text)
1049+
.collect::<Vec<_>>()
1050+
.join("\n");
1051+
1052+
assert!(
1053+
plain.contains("✓ passes 12ms"),
1054+
"rendered preview:\n{plain}"
1055+
);
1056+
assert!(!plain.contains('\u{1b}'));
1057+
assert!(!plain.contains("[32m"));
1058+
assert!(!plain.contains("[2m"));
1059+
}
1060+
1061+
#[test]
1062+
fn render_background_task_message_uses_swarm_flavor_for_swarm_tool() {
10631063
crate::tui::markdown::set_center_code_blocks(false);
10641064
let msg = DisplayMessage::background_task(
10651065
"**Background task** `bg777` · `run_plan (6 nodes, deep mode)` (`swarm`) · ✓ completed · 92.4s · exit 0\n\n```text\nSwarm plan reached terminal/blocked state after 9 loop(s). completed=6 blocked=0 cycles=0 active=0 assignments=8\n```\n\n_Full output:_ `bg action=\"output\" task_id=\"bg777\"`",
@@ -3987,10 +3987,25 @@ fn render_tool_message_full_inline_mode_shows_full_diff() {
39873987

39883988
assert!(!plain.contains("more changes"), "plain={plain}");
39893989
assert!(plain.contains("old line 4"), "plain={plain}");
3990+
let source_text = lines
3991+
.iter()
3992+
.filter(|line| extract_line_text(line).starts_with("│ "))
3993+
.flat_map(|line| {
3994+
line.spans
3995+
.iter()
3996+
.skip(if line.spans[0].content.contains('↪') {
3997+
1
3998+
} else {
3999+
2
4000+
})
4001+
})
4002+
.map(|span| span.content.as_ref())
4003+
.collect::<String>();
39904004
assert!(
39914005
source_text.contains("new line 4 suffix_4_abcdefghijklmnopqrstuvwxyz0123456789"),
39924006
"plain={plain}"
39934007
);
4008+
assert!(lines.iter().all(|line| line.width() <= 39), "plain={plain}");
39944009
assert!(!plain.contains('…'), "plain={plain}");
39954010
assert_eq!(plain.matches("+7 -7").count(), 1, "plain={plain}");
39964011
assert_eq!(extract_line_text(lines.last().unwrap()), "╰─");
@@ -4024,25 +4039,10 @@ fn render_tool_message_memory_recall_centered_mode_left_aligns_with_padding() {
40244039
)
40254040
.to_string(),
40264041
tool_calls: Vec::new(),
4027-
let source_text = lines
4028-
.iter()
4029-
.filter(|line| extract_line_text(line).starts_with("│ "))
4030-
.flat_map(|line| {
4031-
line.spans
4032-
.iter()
4033-
.skip(if line.spans[0].content.contains('↪') {
4034-
1
4035-
} else {
4036-
2
4037-
})
4038-
})
4039-
.map(|span| span.content.as_ref())
4040-
.collect::<String>();
40414042
duration_secs: None,
40424043
title: None,
40434044
tool_data: Some(crate::message::ToolCall {
40444045
id: "call_memory_recall_centered".to_string(),
4045-
assert!(lines.iter().all(|line| line.width() <= 39), "plain={plain}");
40464046
name: "memory".to_string(),
40474047
input: serde_json::json!({
40484048
"action": "recall",

0 commit comments

Comments
 (0)