Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Merge main into feat/tui-panel-sizes — New harness keeps main's side chooser, sized as a Form panel

Tim66fd7158b13a
diff --cc tui/src/new_harness.rs
index ef3123ec2,2481006f9..2821b105b
--- a/tui/src/new_harness.rs
+++ b/tui/src/new_harness.rs
@@@ -1719,8 -1948,7 +1948,9 @@@ mod tests
assert_eq!(hit.intersection(area), *hit);
}
if form.area.width > 0 {
+ // The form's panel: its own height, one size and place whatever is open.
+ assert_eq!(form.area, crate::settings::area(area, crate::settings::PanelSize::Form, view::HEIGHT));
+ assert!(form.area.width <= 60 && form.area.height <= 17);
let left = form.area.x - area.x;
let right = area.right() - form.area.right();
assert!(left.abs_diff(right) <= 1, "not centered in {area:?}");
diff --cc tui/src/new_harness/view.rs
index a0b86be94,616a847cd..8b2bf370b
--- a/tui/src/new_harness/view.rs
+++ b/tui/src/new_harness/view.rs
@@@ -46,15 -46,10 +46,14 @@@ pub(super) fn put(buf: &mut Buffer, x:
buf.set_stringn(x, y, out, width as usize, style);
}
- /// The most fields the form shows (Agent, Project, Options, Model, Approvals, Profile, Branch,
- /// Worktree, Create).
- const MOST_FIELDS: u16 = 9;
- /// The form's height: its most fields, two rows apart, two rows over them — the same collapsed or
- /// expanded, so it does not move.
- pub(super) const HEIGHT: u16 = 2 + MOST_FIELDS * 2;
++/// The form's height: enough rows for every agent's settings, the same whatever is open, so
++/// changing agents or opening an editor never moves it.
++pub(super) const HEIGHT: u16 = 17;
+
/// The form's surface, as the settings panel draws its own: filled, no border.
- fn panel(buf: &mut Buffer, r: Rect, base: Style) { crate::settings::fill(buf, r, base) }
+ fn panel(buf: &mut Buffer, r: Rect, base: Style) {
+ crate::settings::fill(buf, r, base)
+ }
pub fn draw(buf: &mut Buffer, body: Rect, form: &mut Form) -> Option<Position> {
form.hits.clear();
@@@ -72,18 -67,34 +71,32 @@@
return None;
}
// The settings panel's colours, and its quiet backdrop over the working panes.
- let crate::settings::Chrome { base, muted, accent, backdrop, .. } = crate::settings::chrome();
+ let crate::settings::Chrome {
+ base,
+ muted,
+ accent,
+ backdrop,
+ ..
+ } = crate::settings::chrome();
crate::settings::backdrop(buf, body, backdrop);
- // The form is a Form panel: centred, as tall as its fields, the one size whatever is open —
- // and a chooser (an agent, a machine, a folder…) opens in its place, as a section of
- // Appearance does, so nothing moves.
- let side = false;
- // Center the form, not the combined form and chooser. Reserve enough rows for every
- // agent's settings so changing agents or opening an editor never moves the form.
- let form_w = body.width.saturating_sub(4).min(60);
- let form_h = body.height.saturating_sub(2).clamp(5, 17);
- let x = body.x + (body.width - form_w) / 2;
- let y = body.y + (body.height - form_h) / 2;
- let r = Rect::new(x, y, form_w, form_h);
++ // The form is a Form panel (settings::area): centred — the form, not the form and its chooser —
++ // and as tall as every agent's settings need, so changing agents or opening an editor never
++ // moves it. A chooser opens beside it where there is room, else in its place.
+ let r = crate::settings::area(body, crate::settings::PanelSize::Form, HEIGHT);
+ let (x, y, form_w, form_h) = (r.x, r.y, r.width, r.height);
- let (child_w, child_h) = (form_w, form_h);
+ let side_w = body.right().saturating_sub(r.right() + 4).min(60);
+ let side = side_w >= 32;
+ let child_w = if side { side_w } else { form_w };
+ let child_h = if side {
+ body.bottom().saturating_sub(y + 1).min(22).max(form_h)
+ } else {
+ form_h
+ };
let fields = form.fields();
+ let fields_y = y + if form_h >= 9 { 3 } else { 1 };
let errors = error_lines(&form.error, form_w.saturating_sub(4) as usize);
- let error_h = errors.len().min(form_h.saturating_sub(4).max(1) as usize) as u16;
+ // Even a long error in a tiny terminal leaves one field (the focused action) visible.
+ let error_h = errors.len().min(r.bottom().saturating_sub(fields_y + 2).max(1) as usize) as u16;
form.area = r;
if form.child.is_none() || side || !form.child_active {
panel(buf, r, base);
diff --cc tui/src/picker.rs
index e1282c6db,1c0ba0202..308f28bf7
--- a/tui/src/picker.rs
+++ b/tui/src/picker.rs
@@@ -391,10 -389,9 +400,10 @@@ impl Picker
// A live list's rows are its order (by urgency), as fzf's are over lines
// drawn to one width: length decides nothing between them.
let mut rank = crate::fzf::rank(&hit, &chars, if self.live { &live_tiebreak } else { &o.tiebreak });
+ rank.insert(0, row.tier as i64);
// --tac: the input read bottom-up, ties too.
rank.push(if o.tac { -(index as i64) } else { index as i64 });
- scored.push((rank, index, hit.positions.iter().map(|p| *p as u32).collect()));
+ scored.push((rank, index, hit.positions.iter().filter(|p| **p < shown_chars).map(|p| *p as u32).collect()));
}
// The keywords behind a row (engine, machine, branch): whole words of three
// letters or more find it, after everything that matched what you see.
diff --cc tui/src/settings.rs
index 1326430dc,0de1cd522..ee24c8248
--- a/tui/src/settings.rs
+++ b/tui/src/settings.rs
@@@ -361,54 -170,13 +361,58 @@@ pub fn put(buf: &mut Buffer, x: u16, y
used as u16
}
-/// Where the panel goes in [body]: centred, and the same size whatever the list holds.
-pub fn area(body: Rect) -> Rect {
- // (Room for a preview that can be read: nine tenths of the window each way, and at least 4
- // columns and 2 rows of it around the panel.)
- let w = (body.width * 9 / 10).min(body.width.saturating_sub(4));
- let h = (body.height * 9 / 10).min(body.height.saturating_sub(2));
- Rect::new(body.x + (body.width - w) / 2, body.y + (body.height - h) / 2, w, h)
+// ── sizes ──
+
+/// A panel's size: Large for a list with a preview, Palette for a short menu near the top, Form
+/// for a form, as tall as its fields.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum PanelSize { Large, Palette, Form }
+
+/// Of the window, in tenths: the most a panel takes each way (a palette's height, its own).
+const SHARE: u16 = 9;
+const PALETTE_SHARE_H: u16 = 7;
+/// Large: as wide as this at most, however wide the window.
+const LARGE_MAX_W: u16 = 160;
+/// (Room for a command's name, its hint and its key apart.)
+const PALETTE_W: u16 = 96;
- const FORM_W: u16 = 80;
++/// (New harness's form: its chooser opens beside it where there is room.)
++const FORM_W: u16 = 60;
++/// A form keeps this many rows however short the window (its action stays on screen), up to the
++/// window's own.
++const FORM_MIN_H: u16 = 5;
+/// A palette's top: this part of the way down the window (in its upper third).
+const PALETTE_TOP: u16 = 6;
+/// A palette's rows around its list: the title, the query, the gaps and the footer.
+const PALETTE_CHROME: u16 = 8;
+/// Around any panel, at least 4 columns and 2 rows of the window.
+const MARGIN_W: u16 = 4;
+const MARGIN_H: u16 = 2;
+
+impl PickerKind {
+ /// Each list's size, in one place: a new kind does not compile until it has one.
+ pub fn size(&self) -> PanelSize {
+ match self {
+ // (Every launcher tab is the same size — Help too — so ←/→ on the tab row never moves it.)
+ PickerKind::Open { .. } | PickerKind::Palette | PickerKind::Projects | PickerKind::Models | PickerKind::Inbox | PickerKind::Machines | PickerKind::Store | PickerKind::Help | PickerKind::Theme
+ | PickerKind::Route { .. } | PickerKind::Messages | PickerKind::Keys | PickerKind::Buffers | PickerKind::Output { .. } | PickerKind::Devices(_) => PanelSize::Large,
+ PickerKind::Commands | PickerKind::Keybinds | PickerKind::Layout => PanelSize::Palette,
+ }
+ }
+}
+
+/// Where a panel of [size] goes in [body]; [content]: the rows it needs (a palette's list rows, a
+/// form's height) — a large panel's size is the window's.
+pub fn area(body: Rect, size: PanelSize, content: u16) -> Rect {
+ let most_w = (body.width * SHARE / 10).min(body.width.saturating_sub(MARGIN_W));
+ let most_h = (body.height * SHARE / 10).min(body.height.saturating_sub(MARGIN_H));
+ let (w, h) = match size {
+ PanelSize::Large => (most_w.min(LARGE_MAX_W), most_h),
+ PanelSize::Palette => (most_w.min(PALETTE_W), content.saturating_add(PALETTE_CHROME).min(body.height * PALETTE_SHARE_H / 10).min(most_h)),
- PanelSize::Form => (most_w.min(FORM_W), content.min(most_h)),
++ PanelSize::Form => (most_w.min(FORM_W), content.min(most_h).max(FORM_MIN_H.min(body.height))),
+ };
+ let x = body.x + (body.width - w) / 2;
+ let y = if size == PanelSize::Palette { body.y + (body.height - h).min(body.height / PALETTE_TOP) } else { body.y + (body.height - h) / 2 };
+ Rect::new(x, y, w, h)
}
/// Draw the panel for [picker] over [body]; returns where the terminal cursor goes (the query),
@@@ -1099,62 -843,6 +1103,62 @@@ mod tests
assert_ne!(a.base.bg, a.selected.bg, "the cursor's row stands out");
}
+ // ── sizes ──
+
+ /// Each size's numbers on a small, a medium and a very wide body.
+ #[test]
+ fn each_size_has_its_numbers_on_small_medium_and_very_wide_bodies() {
+ let small = Rect::new(0, 0, 40, 12);
+ assert_eq!(area(small, PanelSize::Large, 0), Rect::new(2, 1, 36, 10));
+ assert_eq!(area(small, PanelSize::Palette, 5), Rect::new(2, 2, 36, 8));
+ assert_eq!(area(small, PanelSize::Form, 20), Rect::new(2, 1, 36, 10));
+ let medium = Rect::new(0, 0, 120, 40);
+ assert_eq!(area(medium, PanelSize::Large, 0), Rect::new(6, 2, 108, 36));
+ // (Rows and chrome; at most seven tenths of the height; in the upper third.)
+ assert_eq!(area(medium, PanelSize::Palette, 5), Rect::new(12, 6, 96, 13));
+ assert_eq!(area(medium, PanelSize::Palette, 100), Rect::new(12, 6, 96, 28));
- assert_eq!(area(medium, PanelSize::Form, 20), Rect::new(20, 10, 80, 20));
++ assert_eq!(area(medium, PanelSize::Form, 20), Rect::new(30, 10, 60, 20));
+ let wide = Rect::new(0, 0, 400, 60);
+ assert_eq!(area(wide, PanelSize::Large, 0), Rect::new(120, 3, 160, 54));
+ assert_eq!(area(wide, PanelSize::Palette, 5), Rect::new(152, 10, 96, 13));
- assert_eq!(area(wide, PanelSize::Form, 20), Rect::new(160, 20, 80, 20));
++ assert_eq!(area(wide, PanelSize::Form, 20), Rect::new(170, 20, 60, 20));
+ }
+
+ /// Each list says its size: the launcher's lists, Models, Machines, Store, Appearance and the
+ /// devices are large; Commands and Help a palette.
+ #[test]
+ fn each_kind_has_its_size() {
+ let open = PickerKind::Open { filter: modal::Filter::All, machine: None, project: None };
+ for k in [open, PickerKind::Models, PickerKind::Machines, PickerKind::Store, PickerKind::Help, PickerKind::Theme, PickerKind::Devices(crate::devices::View::Machines)] { assert_eq!(k.size(), PanelSize::Large, "{k:?}") }
+ for k in [PickerKind::Commands, PickerKind::Keybinds] { assert_eq!(k.size(), PanelSize::Palette, "{k:?}") }
+ }
+
+ /// Commands is a palette near the top, narrower than the harnesses' panel; its height does not
+ /// change as a search narrows it.
+ #[test]
+ fn commands_is_a_palette_narrower_than_harnesses() {
+ let app = app((200, 51));
+ let body = Rect::new(0, 0, 200, 50);
+ let mut c = Picker::new("Commands", "Type a command");
+ c.set_rows(modal::command_rows_for(&app, false, false));
+ draw(&mut Buffer::empty(body), &app, body, &PickerKind::Commands, &mut c);
+ let mut h = Picker::new("harnesses", "");
+ draw(&mut Buffer::empty(body), &app, body, &PickerKind::Open { filter: modal::Filter::All, machine: None, project: None }, &mut h);
+ let (cr, hr) = (c.screen_area.get(), h.screen_area.get());
+ assert!(cr.width < hr.width, "{cr:?} {hr:?}");
+ assert!(cr.y < body.height / 3, "{cr:?}");
+ c.set_query("lay");
+ draw(&mut Buffer::empty(body), &app, body, &PickerKind::Commands, &mut c);
+ assert_eq!(c.screen_area.get(), cr);
+ let mut help = Picker::new("help", "");
+ help.set_rows(modal::mode_rows(&app));
+ draw(&mut Buffer::empty(body), &app, body, &PickerKind::Help, &mut help);
+ let before = help.screen_area.get();
+ help.set_query("zzz");
+ draw(&mut Buffer::empty(body), &app, body, &PickerKind::Help, &mut help);
+ assert_eq!(help.screen_area.get(), before, "the palette does not jump as you type");
+ }
+
#[test]
fn every_layout_tiles_the_screen_without_overlap() {
let r = Rect::new(0, 0, 50, 16);