Skip to content

Commit b3d8789

Browse files
committed
Place inline swarm beside pinned todos on wide terminals
1 parent 1e5536d commit b3d8789

3 files changed

Lines changed: 119 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,16 @@ fn draw_inner(frame: &mut Frame, app: &dyn TuiState) {
29412941
// the bottom chrome and shoves the transcript up: reacting to raw
29422942
// frame-by-frame dock visibility made the strip pop in and out and the
29432943
// whole screen bounce (flicker).
2944+
let pinned_width = chat_area.width.saturating_sub(u16::from(
2945+
app.chat_native_scrollbar() && last_chat_scrollbar_visible(),
2946+
));
2947+
let pinned_width = pinned_width.saturating_sub(left_aligned_content_inset(
2948+
pinned_width,
2949+
app.centered_mode(),
2950+
));
2951+
let swarm_beside_todos = viewport::swarm_beside_pinned_todos(app, pinned_width);
29442952
let swarm_strip_lines: Vec<Line<'static>> = if !swarm_page_active
2953+
&& !swarm_beside_todos
29452954
&& app.inline_swarm_gallery_active()
29462955
&& (app.swarm_panel_focused() || !super::info_widget::swarm_strip_stands_down_for_dock())
29472956
{

‎crates/jcode-tui/src/tui/ui_tests/pinned_todo_regressions.rs‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,64 @@ fn todo_payload() -> String {
3636
.to_string()
3737
}
3838

39+
#[test]
40+
fn pinned_todos_share_top_band_with_swarm_only_on_wide_terminals() {
41+
let _render_lock = viewport_snapshot_test_lock();
42+
with_pinned_todos_config(|| {
43+
let member = crate::protocol::SwarmMemberStatus {
44+
session_id: "test-worker".into(),
45+
friendly_name: Some("placement-worker".into()),
46+
status: "running".into(),
47+
detail: Some("Checking layout".into()),
48+
task_label: None,
49+
role: None,
50+
is_headless: Some(true),
51+
live_attachments: None,
52+
status_age_secs: Some(1),
53+
output_tail: None,
54+
report_back_to_session_id: None,
55+
todo_progress: None,
56+
todo_items: Vec::new(),
57+
runtime: Default::default(),
58+
};
59+
let state = TestState {
60+
pinned_todos_payload: Some(todo_payload()),
61+
swarm_members: vec![member],
62+
..Default::default()
63+
};
64+
for width in [80, 119, 120, 160, 240] {
65+
let (lines, _) = viewport::pinned_todo_band_lines(&state, width, 36);
66+
let text = lines
67+
.iter()
68+
.map(ToString::to_string)
69+
.collect::<Vec<_>>()
70+
.join("\n");
71+
assert_eq!(
72+
text.contains("placement-worker"),
73+
width >= 120,
74+
"{width}: {text}"
75+
);
76+
assert!(lines.iter().all(|line| line.width() <= width as usize));
77+
if width >= 120 {
78+
let row = lines
79+
.iter()
80+
.find(|line| line.to_string().contains("placement-worker"))
81+
.unwrap();
82+
let text = row.to_string();
83+
let prefix = text.split("placement-worker").next().unwrap();
84+
assert!(unicode_width::UnicodeWidthStr::width(prefix) >= width as usize / 2);
85+
}
86+
}
87+
clear_flicker_frame_history_for_tests();
88+
let mut terminal = Terminal::new(TestBackend::new(160, 36)).unwrap();
89+
terminal
90+
.draw(|frame| crate::tui::ui::draw(frame, &state))
91+
.unwrap();
92+
let text = terminal_text(&terminal);
93+
assert_eq!(text.matches("placement-worker").count(), 1, "{text}");
94+
});
95+
}
96+
3997
fn hidden_todo(payload: &str) -> DisplayMessage {
4098
DisplayMessage {
4199
role: "tool".into(),

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

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ pub(super) fn draw_messages(
452452
.y
453453
.saturating_add(prompt_preview_lines)
454454
.saturating_add(line as u16),
455-
width: text_render_area.width,
455+
width: if swarm_beside_pinned_todos(app, text_render_area.width) {
456+
text_render_area.width / 2
457+
} else {
458+
text_render_area.width
459+
},
456460
height: 1,
457461
}
458462
}));
@@ -1446,20 +1450,62 @@ fn windowed_min(widths: &[u16], window: usize) -> Vec<u16> {
14461450
out
14471451
}
14481452

1449-
/// Lines for the pinned todo band. Background tasks render in the
1450-
/// `background` info widget, not here.
1453+
/// Whether the pinned band has room for a separate swarm column.
1454+
pub(crate) fn swarm_beside_pinned_todos(app: &dyn TuiState, width: u16) -> bool {
1455+
width >= 120
1456+
&& crate::config::config().display.pin_todos
1457+
&& app.pinned_todos_payload().is_some()
1458+
&& app.inline_swarm_gallery_active()
1459+
&& !app.inline_swarm_members().is_empty()
1460+
&& !pinned_todo_band_lines_for_payload(
1461+
app.pinned_todos_payload(),
1462+
app.pinned_todos_expanded(),
1463+
app.diff_mode(),
1464+
width / 2,
1465+
3,
1466+
)
1467+
.0
1468+
.is_empty()
1469+
}
1470+
14511471
pub(crate) fn pinned_todo_band_lines(
14521472
app: &dyn TuiState,
14531473
width: u16,
14541474
viewport_height: u16,
14551475
) -> (Vec<Line<'static>>, Option<usize>) {
1456-
pinned_todo_band_lines_for_payload(
1476+
let beside = swarm_beside_pinned_todos(app, width);
1477+
let todo_width = if beside { width / 2 } else { width };
1478+
let (mut lines, more) = pinned_todo_band_lines_for_payload(
14571479
app.pinned_todos_payload(),
14581480
app.pinned_todos_expanded(),
14591481
app.diff_mode(),
1460-
width,
1482+
todo_width,
14611483
viewport_height,
1462-
)
1484+
);
1485+
if beside && !lines.is_empty() {
1486+
let right_width = width.saturating_sub(todo_width + 2) as usize;
1487+
let members = app.inline_swarm_members();
1488+
let swarm = super::info_widget::swarm_gallery::render_swarm_strip_lines(
1489+
&members,
1490+
app.swarm_panel_selected(),
1491+
app.swarm_panel_focused(),
1492+
&crate::tui::keybind::swarm_panel_focus_key_label(),
1493+
(app.animation_elapsed() * jcode_tui_render::swarm_gallery::STRIP_SPINNER_FPS) as usize,
1494+
right_width,
1495+
((viewport_height as usize) / 3).clamp(3, 16),
1496+
);
1497+
lines.resize_with(lines.len().max(swarm.len()), || Line::from(""));
1498+
for (index, line) in lines.iter_mut().enumerate() {
1499+
*line = super::truncate_line_with_ellipsis_to_width(line, todo_width as usize);
1500+
if let Some(right) = swarm.get(index) {
1501+
line.spans.push(Span::raw(
1502+
" ".repeat((todo_width as usize).saturating_sub(line.width()) + 2),
1503+
));
1504+
line.spans.extend(right.spans.clone());
1505+
}
1506+
}
1507+
}
1508+
(lines, more)
14631509
}
14641510

14651511
/// Pinned todo band for an arbitrary todo payload. Shared by the live chat

0 commit comments

Comments
 (0)