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-command-panel

Time82dc4b77291
diff --cc tui/src/commands.rs
index 228baa0be,6a53e4597..31c04342e
--- a/tui/src/commands.rs
+++ b/tui/src/commands.rs
@@@ -85,7 -85,7 +85,8 @@@ pub const COMMANDS: &[(&str, &str, &str
("confirm-before", "confirm", "Ask y/n before a command"),
("new-harness", "newh", "New harness: [engine] [@machine] [folder] — or choose"),
("new-terminal", "newt", "A shell on this pane's machine"),
+ ("choose-command", "choosec", "Every command and setting by name (C-b Enter)"),
+ ("take-control", "take", "Reclaim control of all panes across the TUI's tabs"),
("clone-harness", "cloneh", "A second harness with this one's history"),
("restart-harness", "restarth", "Restart this harness"),
("pause-harness", "pauseh", "Pause this harness (the conversation is kept)"),
@@@ -3484,7 -3480,7 +3485,8 @@@ fn run_words_in(app: &mut App, words: &
}
"new-harness" => { if words.len() < 2 { input::run(app, "new") } else { input::new_harness_words(app, &words[1..]) } }
"new-terminal" => input::run(app, "terminal"),
+ "choose-command" => input::run(app, "commands"),
+ "take-control" => app.take_control(),
// A harness's verbs, on -t's harness (the hook's in a harness-* hook), else the focused
// pane's; from a shell -t is needed, and one mid-turn is restarted or paused only with -y
// (the keys ask first).
diff --cc tui/src/input.rs
index fd9a227ae,80b488735..546c1410c
--- a/tui/src/input.rs
+++ b/tui/src/input.rs
@@@ -657,16 -650,9 +659,16 @@@ fn fill_rows(app: &App, kind: &PickerKi
picker.empty = "Nobody is waiting on you.".into();
}
PickerKind::Machines => {
+ let was = picker.current_id();
picker.set_rows(modal::machine_rows(app));
+ // Come to from another list (`@`): the cursor on the machine you are on — the focused
+ // pane's, else this one — with its preview beside it. A refresh leaves it where it is.
- if !was.is_some_and(|w| app.fleet.machines.iter().any(|m| m.id == w)) {
++ if !was.is_some_and(|w| app.fleet.visible_machines().any(|m| m.id == w)) {
+ let here = app.focused().and_then(|p| app.panes.get(&p)).map(|p| p.machine_id.clone()).filter(|m| !m.is_empty()).unwrap_or_else(|| app.fleet.local_id.clone());
+ picker.select(&here);
+ }
- let up = app.fleet.machines.iter().filter(|m| m.usable()).count();
- picker.status = format!("{up}/{} connected", app.fleet.machines.len());
+ let up = app.fleet.visible_machines().filter(|m| m.usable()).count();
+ picker.status = format!("{up}/{} connected", app.fleet.visible_machines().count());
picker.hints = vec![("enter", "its harnesses"), ("M-n", "new there"), ("C-t", "terminal there"), ("M-l", "link")];
}
PickerKind::Layout => { picker.set_rows(modal::layout_rows()); picker.hints = vec![("enter", "apply")] }
diff --cc tui/src/main.rs
index 46c5718cb,1de0f08d2..2261e0ea0
--- a/tui/src/main.rs
+++ b/tui/src/main.rs
@@@ -300,12 -291,8 +300,13 @@@ async fn run(config: config::Config) -
f.rest = f.rest[starts[k]..].to_vec();
}
}
+ // `hn <command>` where the command is an in-TUI one (theme, palette, layout…): tmux's CLI
+ // would answer "unknown command", because these are not tmux commands. The client starts and
- // runs it itself, once the launcher is up — as `;`'s chain is (`start_then`).
- let gui = !f.rest.is_empty() && f.rest.iter().all(|w| crate::input::is_command(w));
++ // runs it itself, once the launcher is up — as `;`'s chain is (`start_then`). A word the
++ // server answers too (take, new, send…) stays the server's.
++ let gui = !f.rest.is_empty() && f.rest.iter().all(|w| crate::input::is_command(w) && !crate::commands::is_command_name(w));
// hn <command>: answered from here (hn ls) or by the running client (a tmux command).
- if let Some(code) = cli::run(&f.rest, explicit, f.socket.as_deref(), f.name.as_deref()).await { std::process::exit(code) }
+ if !gui { if let Some(code) = cli::run(&f.rest, explicit, f.socket.as_deref(), f.name.as_deref()).await { std::process::exit(code) } }
// -L name, starting a client: its socket's name.
if let Some(n) = &f.name { unsafe { std::env::set_var("HN_SOCKET_NAME", n) } }
// hn new -s work / hn attach -t work: the session this client starts in.
diff --cc tui/src/modal.rs
index adf7e48dd,47ef2f4d0..8db5a163d
--- a/tui/src/modal.rs
+++ b/tui/src/modal.rs
@@@ -554,95 -525,13 +554,96 @@@ pub fn layout_rows() -> Vec<Row>
Preset::ALL.iter().enumerate().map(|(i, (_, name, detail))| Row::new(i.to_string(), *name).detail(vec![span(*detail, fg(theme::MUTED))])).collect()
}
+/// `hn theme`: every choice in the config file's `[look]` table, one per row, the current value
+/// marked. Picking a row applies it live and writes it back to `tui.toml` — so the file stays the
+/// single place the look is described.
+/// The look/theme picker, level one: the sections. Right/Enter opens one's options in the same
+/// list; the right pane previews the one the cursor is on.
+pub fn theme_sections(app: &App) -> Vec<Row> {
+ let o = &app.options;
+ let status = o.get("pane-border-status", "", None).unwrap_or_else(|| "top".into());
+ // (Named as its options are: the highlighted border, or the rest blurred.)
+ let focus = if o.focus_style() == "surface" { "blurred" } else { "border" };
+ let orientation = o.look_orientation().to_string();
+ let layout_preset = o.get("@hn-layout-preset", "", None).unwrap_or_else(|| "auto".into());
+ let theme = o.get("@hn-theme", "", None).unwrap_or_default();
+
+ let sec = |id: &str, title: &str, detail: &str, cur: &str| Row::new(id, title)
+ .detail(vec![span(detail, fg(theme::MUTED))])
+ .right(if cur.is_empty() { "—".into() } else { cur.to_string() });
+
+ vec![
+ // (The lines' glyphs and tmux's arrow indicators are tmux.conf's to set: with every pane its
+ // own box, coloured when focused, they say nothing more.)
+ sec("section:status", "Pane titles", "pane-border-status", &status),
+ sec("section:focus", "Focus", "focus_style", focus),
+ sec("section:split", "Split direction", "layout_orientation", &orientation),
+ sec("section:layout", "Layout", "@hn-layout-preset", &layout_preset),
+ sec("section:theme", "Theme", "bundled terminal themes", if theme.is_empty() { "terminal" } else { &theme }),
+ // ── status bar ──
+ sec("section:bar", "Status bar", "status_bar", status_bar_of(app)),
+ sec("section:boxes", "Borders", "every pane its own box", if border_style_of(app) == "box" { "on" } else { "off" }),
+ ]
+}
+
+// ── status bar ──
+
+/// Where the status bar is: `@hn-status-bar`, or (none said) where tmux.conf's status-position put it.
+fn status_bar_of(app: &App) -> &'static str { match app.options.status_bar() { "bottom" if app.status_top => "top", b => b } }
+
+/// How panes are set apart: `box` unless `@hn-border line`.
+fn border_style_of(app: &App) -> &'static str { if app.options.get("@hn-border", "", None).as_deref() == Some("line") { "line" } else { "box" } }
+
+/// The look/theme picker, level two: the options of one section. Enter on one applies it (and the
+/// ▼ moves to it); Left/Esc returns to the section list.
+pub fn theme_options(app: &App, section: &str) -> Vec<Row> {
+ let o = &app.options;
+ let mark = |is: bool| if is { "✓ " } else { " " };
+ let lead = |is: bool| vec![span(mark(is), fg(if is { theme::accent() } else { theme::MUTED }))];
+ let current = |key: &str, default: &str| o.get(key, "", None).unwrap_or_else(|| default.into());
+ let opt = |id: String, label: &str, picked: bool, hint: &str| {
+ Row::new(id, label).lead(lead(picked)).detail(vec![span(if picked { "current" } else { hint }, fg(theme::MUTED))])
+ };
+ match section {
+ "status" => { let cur = current("pane-border-status", "top");
+ ["off", "top", "bottom"].iter().map(|v| opt(format!("border_status:{v}"), *v, cur == *v, "pane-border-status")).collect() }
+ "indicators" => { let cur = current("pane-border-indicators", "colour");
+ ["off", "colour", "arrows", "both"].iter().map(|v| opt(format!("border_indicators:{v}"), *v, cur == *v, "pane-border-indicators")).collect() }
+ "border" => { let cur = current("pane-border-lines", "single");
+ ["single", "double", "heavy", "simple", "number"].iter().map(|v| opt(format!("border_lines:{v}"), *v, cur == *v, "pane-border-lines")).collect() }
+ "focus" => { let cur = o.focus_style().to_string();
+ ["line", "surface"].iter().map(|v| opt(format!("focus:{v}"), if *v == "line" { "border" } else { "blurred" }, cur == *v, "focus_style")).collect() }
+ "split" => { let cur = o.look_orientation().to_string();
+ ["auto", "vertical", "horizontal"].iter().map(|v| opt(format!("layout_orientation:{v}"), *v, cur == *v, "layout_orientation")).collect() }
+ "layout" => { let cur = current("@hn-layout-preset", "auto");
+ ["auto", "even-horizontal", "even-vertical", "main-horizontal", "main-vertical", "tiled"].iter().map(|v| opt(format!("layout_preset:{v}"), *v, cur == *v, "@hn-layout-preset")).collect() }
+ "theme" => {
+ let cur = o.get("@hn-theme", "", None).unwrap_or_default();
+ // First, no theme: the terminal's own colours.
+ let native = Row::new("theme:", "Terminal default").extra("none default terminal").lead(lead(cur.is_empty()));
+ std::iter::once(native).chain(TERMINAL_THEMES.iter().map(|t| {
+ let picked = cur == t.name;
+ Row::new(format!("theme:{}", t.name), t.name).extra(t.name).lead(lead(picked))
+ })).collect()
+ }
+ // ── status bar ──
+ "bar" => { let cur = status_bar_of(app);
+ [("bottom", "tmux's status line, at the bottom"), ("top", "tmux's status line, at the top"), ("left", "a bar down the left: windows and their panes, machines"), ("right", "a bar down the right")]
+ .iter().map(|(v, hint)| opt(format!("status_bar:{v}"), v, cur == *v, hint)).collect() }
+ "boxes" => { let cur = border_style_of(app);
+ [("box", "on", "every pane its own box"), ("line", "off", "tmux's lines between panes")]
+ .iter().map(|(v, label, hint)| opt(format!("border_style:{v}"), label, cur == *v, hint)).collect() }
+ _ => vec![],
+ }
+}
+
pub fn new_machine_rows(app: &App, prefer: &str) -> Vec<Row> {
- let mut rows: Vec<Row> = app.fleet.machines.iter().filter(|m| m.usable()).map(|m| {
+ let prefer = app.fleet.launch_machine_id(prefer);
+ let mut rows: Vec<Row> = app.fleet.visible_machines().filter(|m| m.usable()).map(|m| {
let running = app.fleet.agents.values().filter(|a| a.machine_id == m.id && a.status == "active").count();
- Row::new(m.id.clone(), m.name.clone())
+ Row::new(m.id.clone(), app.fleet.machine_name(&m.id))
- .lead(vec![span(if m.id == prefer { "● " } else { "○ " }, fg(if m.id == prefer { theme::accent() } else { theme::ONLINE }))])
+ .lead(vec![span(if m.id == prefer { "✓ " } else { " " }, fg(theme::accent()))])
.detail(vec![span(format!("{}{running} running", if m.local { "this computer · " } else { "" }), fg(theme::MUTED))])
}).collect();
rows.sort_by_key(|r| r.id != prefer);
diff --cc tui/src/mouse.rs
index 0294a496c,a562a9dd2..1fde805d6
--- a/tui/src/mouse.rs
+++ b/tui/src/mouse.rs
@@@ -251,8 -245,8 +251,16 @@@ fn check(app: &mut App, m: &mut Event,
let body = app.body();
if px > body.width as u32 || py > body.height as u32 { return None }
let geoms = app.visible_layout_geoms();
++ // A top pane's title, on the window's first row (tmux's pane status line there), is the
++ // pane's in hn's boxes and surfaces: a click focuses it and reaches no program.
++ if py == 0 && (app.options.box_panes() || app.options.pane_look()) {
++ if let Some((id, _)) = geoms.iter().find(|(_, g)| g.y == 1 && px >= g.x && px < g.x + g.w) {
++ m.wp = Some(*id);
++ place = Some(keys::PANE);
++ }
++ }
// A border (a zoomed window has none): the column after a pane or the row below it.
-- if !app.tab().zoomed {
++ if place.is_none() && !app.tab().zoomed {
if let Some((id, _)) = geoms.iter().find(|(_, g)| (g.x + g.w == px && g.y <= 1 + py && g.y + g.h >= py) || (g.y + g.h == py && g.x <= 1 + px && g.x + g.w >= px)) {
m.wp = Some(*id);
place = Some(keys::BORDER);
diff --cc tui/src/new_harness.rs
index 7f970fe07,da2cee2e9..2a576563e
--- a/tui/src/new_harness.rs
+++ b/tui/src/new_harness.rs
@@@ -1561,23 -1581,64 +1579,81 @@@ mod tests
app
}
+ /// Opening a chooser beside the form (an agent, here) leaves the form where it was, on a wide
+ /// window and a narrow one.
+ #[tokio::test]
+ async fn the_form_stays_put_when_a_chooser_opens() {
+ let mut app = app();
+ open(&mut app, None, Some("/home/dev/project".into()));
+ let Some(Modal::NewHarness(mut form)) = app.modal.take() else { panic!() };
+ for body in [Rect::new(0, 0, 150, 41), Rect::new(0, 0, 90, 30)] {
+ form.child = None;
+ draw(&mut Buffer::empty(body), body, &mut form);
+ let alone = form.area;
+ child(&mut app, &mut form, Choice::Agent, "codex");
+ draw(&mut Buffer::empty(body), body, &mut form);
+ assert_eq!(form.area, alone, "the form moved at {}x{}", body.width, body.height);
+ }
+ }
+
+ #[tokio::test]
+ async fn local_shell_entry_does_not_override_the_registered_launch_machine() {
+ let mut app = app();
+ let shell = crate::local::MACHINE;
+ app.fleet.machines.insert(0, crate::fleet::Machine {
+ id: shell.into(), name: "m0".into(), local: true,
+ status: "running".into(), reach: crate::fleet::Reach::Ready,
+ });
+ for explicit in [None, Some(shell.into())] {
+ open(&mut app, explicit, None);
+ let Some(Modal::NewHarness(form)) = &app.modal else { panic!() };
+ assert_eq!(form.draft.machine, "local");
+ assert_eq!(form.project_label(), "studio:New Folder");
+ for rows in [modal::machine_rows(&app), modal::new_machine_rows(&app, shell)] {
+ assert_eq!(rows.len(), 1);
+ assert_eq!(rows[0].id, "local");
+ assert_eq!(rows[0].label, "studio");
+ }
+ }
+ // Recent local-shell folders use that same machine and collapse duplicate paths.
+ for machine in [shell, "local"] {
+ let agent = crate::fleet::agent_from(machine, &json!({"id":"agent", "engine":"terminal", "project":{"cwd":"/home/dev/repo"}}), None);
+ app.fleet.agents.insert(agent.key(), agent);
+ }
+ let Some(Modal::NewHarness(form)) = &app.modal else { panic!() };
+ let rows = project_rows(&app, &form.draft);
+ let recent: Vec<_> = rows.iter().filter(|r| r.id.starts_with("at:")).collect();
+ assert_eq!(recent.len(), 1);
+ assert_eq!(recent[0].id, "at:local\t/home/dev/repo");
+ assert_eq!(recent[0].label, "studio:~/repo");
+ }
+
+ #[tokio::test]
+ async fn daemon_return_redirects_an_idle_local_draft_but_keeps_a_pending_receipt() {
+ for pending in [false, true] {
+ let mut app = app();
+ let shell = crate::local::MACHINE;
+ app.fleet.machines.insert(0, crate::fleet::Machine {
+ id: shell.into(), name: "m0".into(), local: true,
+ status: "running".into(), reach: crate::fleet::Reach::Ready,
+ });
+ app.homes.insert(shell.into(), "/home/dev".into());
+ app.fleet.machine_mut("local").unwrap().reach = crate::fleet::Reach::Offline;
+ open(&mut app, Some(shell.into()), Some("/home/dev/repo".into()));
+ let Some(Modal::NewHarness(form)) = &mut app.modal else { panic!() };
+ if pending {
+ form.attempt = Some(Creation { id: "original".into(), machine: shell.into(), session: app.session_id });
+ }
+ app.fleet.machine_mut("local").unwrap().reach = crate::fleet::Reach::Ready;
+ app.fleet.machine_mut("local").unwrap().name = "office".into();
+ refresh(&mut app);
+ let Some(Modal::NewHarness(form)) = &app.modal else { panic!() };
+ assert_eq!(form.draft.machine, if pending { shell } else { "local" });
+ assert_eq!(form.project_label(), "office:~/repo");
+ if pending { assert_eq!(form.attempt.as_ref().unwrap().machine, shell); }
+ }
+ }
+
#[tokio::test]
async fn draft_survives_picker_escape_and_late_refresh() {
let mut app = app();
@@@ -1613,29 -1674,63 +1689,58 @@@
}
#[tokio::test]
- async fn form_and_picker_fit_every_terminal_size() {
- async fn compact_form_is_centered_and_stays_anchored_at_every_terminal_size() {
++ async fn the_form_is_the_panel_centered_and_anchored_at_every_terminal_size() {
let mut app = app();
open(&mut app, None, None);
let Some(Modal::NewHarness(mut form)) = app.modal.take() else {
panic!()
};
- for expanded in [false, true] {
- form.expanded = expanded;
- for chooser in [false, true] {
- if chooser {
- child(&mut app, &mut form, Choice::Agent, "");
- } else {
- form.child = None;
- }
- for width in [1, 10, 21, 22, 45, 80, 109, 110, 150] {
- for height in [1, 4, 5, 10, 14, 24, 42] {
- let area = Rect::new(0, 0, width, height);
- let mut buf = Buffer::empty(area);
- if let Some(cursor) = draw(&mut buf, area, &mut form) {
- assert!(area.contains(cursor), "{area:?} {cursor:?}");
+ for width in [
+ 1, 10, 21, 22, 45, 80, 109, 110, 120, 122, 123, 124, 150, 220,
+ ] {
+ for height in [1, 4, 5, 10, 14, 24, 42] {
+ let area = Rect::new(3, 2, width, height);
+ let mut anchor = None;
+ for expanded in [false, true, false] {
+ form.expanded = expanded;
+ for chooser in [None, Some(Choice::Agent), Some(Choice::Clone), None] {
+ if let Some(kind) = chooser {
+ child(&mut app, &mut form, kind, "");
+ } else {
+ form.child = None;
}
- for (hit, _) in &form.hits {
- assert_eq!(hit.intersection(area), *hit);
+ for active in [false, true] {
+ form.child_active = active;
+ let mut buf = Buffer::empty(area);
+ if let Some(cursor) = draw(&mut buf, area, &mut form) {
+ assert!(area.contains(cursor), "{area:?} {cursor:?}");
+ }
+ for (hit, _) in &form.hits {
+ assert_eq!(hit.intersection(area), *hit);
+ }
+ if form.area.width > 0 {
- assert!(form.area.width <= 52);
++ // The menus' panel: one size and place whatever is open.
++ assert_eq!(form.area, crate::settings::area(area));
+ let left = form.area.x - area.x;
+ let right = area.right() - form.area.right();
+ assert!(left.abs_diff(right) <= 1, "not centered in {area:?}");
+ if !expanded {
+ let top = form.area.y - area.y;
+ let bottom = area.bottom() - form.area.bottom();
+ assert!(top.abs_diff(bottom) <= 1, "not centered in {area:?}");
+ }
+ let position = (form.area.x, form.area.y, form.area.width);
+ assert_eq!(
+ *anchor.get_or_insert(position),
+ position,
+ "form moved in {area:?}: expanded={expanded}, active={active}"
+ );
+ assert_eq!(form.area.intersection(area), form.area);
+ }
++ // A chooser opens in the form's place, as a section of Appearance does.
+ if form.child_area.width > 0 {
- assert_eq!(form.child_area.intersection(area), form.child_area);
- assert_eq!(form.child_area.y, form.area.y);
- if form.child_area.x == form.area.x {
- assert!(active && width < 150);
- assert_eq!(form.child_area.width, form.area.width);
- } else {
- assert_eq!(form.child_area.x, form.area.right() + 2);
- }
++ assert_eq!(form.child_area, form.area);
+ }
}
}
}
diff --cc tui/src/options/mod.rs
index 1fe2ff875,733edbfad..bd299c47c
--- a/tui/src/options/mod.rs
+++ b/tui/src/options/mod.rs
@@@ -269,20 -243,6 +268,22 @@@ impl Store
/// Reduce motion independently of the status/pane appearance.
pub fn animations(&self) -> bool { !matches!(self.get("@hn-animations", "", None).as_deref(), Some("off" | "0" | "no")) }
+ // ── status bar ──
+
+ /// `@hn-status-bar` (tui.toml `status_bar`): `bottom` or `top` (tmux's status line, where
+ /// status-position puts it), or `left`/`right` — the bar down that side.
+ pub fn status_bar(&self) -> &'static str {
+ match self.get("@hn-status-bar", "", None).as_deref() { Some("left") => "left", Some("right") => "right", Some("top") => "top", _ => "bottom" }
+ }
+
+ /// `@hn-border` box (the default): every pane its own frame, a cell apart. `line` is tmux's
- /// shared lines; the blurred surfaces and `@hn-look tmux` draw as they always have.
++ /// shared lines; the blurred surfaces, `@hn-look tmux` and `@hn-look classic` (the earlier
++ /// line borders) draw as they always have.
+ pub fn box_panes(&self) -> bool {
- !self.tmux_look() && !self.pane_look() && self.get("@hn-border", "", None).as_deref() != Some("line")
++ !self.tmux_look() && !self.pane_look() && self.get("@hn-look", "", None).as_deref() != Some("classic")
++ && self.get("@hn-border", "", None).as_deref() != Some("line")
+ }
+
/// The default for a name: hn's, or tmux's under `@hn-look tmux`.
fn default_of(&self, name: &str, inherit_window_style: bool) -> Option<String> {
if LOOK.contains(&name) && self.tmux_look() { tmux_defaults().get(name).cloned() }
diff --cc tui/src/settings.rs
index 764d3c441,000000000..547234194
mode 100644,000000..100644
--- a/tui/src/settings.rs
+++ b/tui/src/settings.rs
@@@ -1,860 -1,0 +1,868 @@@
+//! The settings panel: `hn theme` drawn as one centred panel in the New Harness style — a quiet
+//! backdrop over the panes, no border, and a fixed size, so it stays put as you step into a
+//! section. The list is on the left; the right is one preview of the whole look (every section at
+//! once), which only changes where the row under the cursor would change it.
+use ratatui::buffer::Buffer;
+use ratatui::layout::{Position, Rect};
+use ratatui::style::{Color, Modifier, Style};
+use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
+
+use crate::app::App;
+use crate::modal::PickerKind;
+use crate::picker::Picker;
+use crate::terminal_themes::{TerminalTheme, TERMINAL_THEMES};
+use crate::theme;
+
+/// `@hn-lists fzf`: hn's lists drawn as fzf draws them (full screen, FZF_DEFAULT_OPTS's look)
+/// rather than as this panel — for those who want fzf's own. Settings and commands stay panels.
+static FZF_LISTS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+
+pub fn set_fzf_lists(on: bool) { FZF_LISTS.store(on, std::sync::atomic::Ordering::Relaxed) }
+
+/// The lists drawn as this panel rather than as fzf's full-screen list: every one, unless
+/// `@hn-lists fzf` asks for fzf's.
+pub fn is_panel(kind: &PickerKind) -> bool {
+ matches!(kind, PickerKind::Theme | PickerKind::Commands | PickerKind::Devices(_) | PickerKind::Models) || !FZF_LISTS.load(std::sync::atomic::Ordering::Relaxed)
+}
+
+/// Whether [kind]'s list reads top-down (↑ toward its first row): fzf's under --layout=reverse,
+/// and the panel's menus; the launcher's lists read bottom-up in the panel too, their query
+/// under them, as fzf's do.
+pub fn top_down(kind: &PickerKind) -> bool {
+ if is_panel(kind) { !crate::modal::is_launcher(kind) } else { theme::fzf().reverse }
+}
+
+/// Step into [section]: its options in the same list, the cursor on the one in use.
+pub fn open_section(app: &App, picker: &mut Picker, section: &str) {
+ picker.theme_in = Some(section.to_string());
+ picker.clear_query();
+ picker.rows.clear();
+ picker.set_rows(crate::modal::theme_options(app, section));
+ let current = picker.rows.iter().find(|r| r.lead.iter().any(|s| s.content.as_ref() == "✓ ")).map(|r| r.id.clone());
+ picker.scroll = 0;
+ if let Some(id) = current { cursor_to(picker, &id) } else { picker.vset(0, 1) }
+}
+
+/// Step back out to the sections, the cursor on the one just left.
+pub fn close_section(app: &App, picker: &mut Picker) {
+ let from = picker.theme_in.take().map(|s| format!("section:{s}"));
+ picker.clear_query();
+ picker.rows.clear();
+ picker.set_rows(crate::modal::theme_sections(app));
+ picker.scroll = 0;
+ if let Some(id) = from { cursor_to(picker, &id) }
+}
+
+/// Settings chosen in the command list: the same panel shows the sections, and Esc comes back.
+pub fn into_settings(app: &App, picker: &mut Picker) {
+ picker.from_commands = true;
+ picker.placeholder = "Search appearance".into();
+ picker.keep_order = true;
+ picker.live = false;
+ picker.theme_in = None;
+ picker.clear_query();
+ picker.rows.clear();
+ picker.set_rows(crate::modal::theme_sections(app));
+ picker.scroll = 0;
+ picker.vset(0, 1);
+}
+
+/// Back from the settings to the command list, the cursor on Settings.
+pub fn back_to_commands(app: &App, picker: &mut Picker) {
+ picker.from_commands = false;
+ picker.theme_in = None;
+ picker.placeholder = "Type a command — appearance, new, layout, models…".into();
+ picker.keep_order = false;
+ picker.live = true;
+ picker.clear_query();
+ picker.rows.clear();
+ picker.set_rows(crate::modal::command_rows_for(app, false));
+ picker.scroll = 0;
+ cursor_to(picker, "cmd:theme");
+}
+
+/// Put the cursor on the row [id] (where the filter shows it).
+pub fn cursor_to(picker: &mut Picker, id: &str) { picker.select(id) }
+
+/// The panel's colours, shared with the New Harness form so the two read as one component:
+/// its surface, muted and accent text, and the backdrop laid over the panes behind it.
+pub struct Chrome { pub base: Style, pub muted: Style, pub accent: Style, pub backdrop: Style, pub selected: Style }
+
+pub fn chrome() -> Chrome {
+ if theme::no_color() {
+ let base = Style::default();
+ return Chrome { base, muted: base.add_modifier(Modifier::DIM), accent: base.add_modifier(Modifier::BOLD), backdrop: base.add_modifier(Modifier::DIM), selected: base.add_modifier(Modifier::REVERSED) };
+ }
+ chrome_for(theme::pane_palette())
+}
+
+/// The panel's colours from [pal] — the theme in use (or the terminal's own colours): the panel is
+/// its surface lifted a little toward the text, the backdrop its surface pushed down, so the panel
+/// stands out in any theme, light or dark.
+pub fn chrome_for(pal: theme::PanePalette) -> Chrome {
+ let (bg, fg) = (pal.surface, pal.foreground);
+ let light = matches!(bg, Color::Rgb(r, g, b) if 299 * r as u32 + 587 * g as u32 + 114 * b as u32 > 128_000);
+ let floor = if light { Color::Rgb(160, 160, 160) } else { Color::Rgb(0, 0, 0) };
+ let panel = mix(bg, fg, if light { 3 } else { 7 });
+ let base = theme::fg(fg).bg(theme::depth_fit(panel));
+ let muted = base.patch(theme::fg(pal.muted));
+ let accent = base.patch(theme::bold(theme::accent()));
+ let backdrop = theme::fg(mix(bg, fg, 18)).bg(theme::depth_fit(mix(bg, floor, 45)))
+ .remove_modifier(Modifier::BOLD | Modifier::REVERSED | Modifier::DIM | Modifier::UNDERLINED);
+ // (The cursor's row: the text's own colour, bold, on a lifted surface — the accent is for the
+ // pointer and the query's mark, not for words.)
+ let selected = base.add_modifier(Modifier::BOLD).bg(theme::depth_fit(mix(panel, fg, 10)));
+ Chrome { base, muted, accent, backdrop, selected }
+}
+
+/// [a] moved [amount] % toward [b] (RGB; any other colour stays as it is).
+fn mix(a: Color, b: Color, amount: u16) -> Color {
+ let (Color::Rgb(ar, ag, ab), Color::Rgb(br, bg, bb)) = (a, b) else { return a };
+ let c = |a: u8, b: u8| ((a as u16 * (100 - amount) + b as u16 * amount) / 100) as u8;
+ Color::Rgb(c(ar, br), c(ag, bg), c(ab, bb))
+}
+
+/// Dim every cell of [area] under the panel, keeping what is drawn there visible.
+pub fn backdrop(buf: &mut Buffer, area: Rect, style: Style) {
+ crate::term_out::clear_extras(area);
+ for y in area.y..area.bottom() { for x in area.x..area.right() { if let Some(c) = buf.cell_mut((x, y)) { c.set_style(style); } } }
+}
+
+/// Fill [r] with the panel's surface — no border: the surface against the backdrop is the edge.
+pub fn fill(buf: &mut Buffer, r: Rect, base: Style) {
+ crate::term_out::clear_extras(r);
+ for y in r.y..r.bottom() { for x in r.x..r.right() { if let Some(c) = buf.cell_mut((x, y)) { c.reset(); c.set_style(base); } } }
+}
+
+/// [text] at (x, y) in at most [width] columns, cut with an ellipsis. Returns the columns used.
+pub fn put(buf: &mut Buffer, x: u16, y: u16, width: u16, text: &str, style: Style) -> u16 {
+ if width == 0 { return 0 }
+ let limit = width as usize;
+ let cut = text.width() > limit;
+ let (mut out, mut used) = (String::new(), 0);
+ for ch in text.chars().filter(|c| !c.is_control()) {
+ let w = ch.width().unwrap_or(0);
+ if used + w > limit - usize::from(cut) { break }
+ out.push(ch);
+ used += w;
+ }
+ if cut { out.push('…'); used += 1 }
+ buf.set_stringn(x, y, out, limit, style);
+ 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)
+}
+
+/// Draw the panel for [picker] over [body]; returns where the terminal cursor goes (the query),
+/// and the rect on the right where the list's own preview goes (the caller draws it: a harness's
+/// preview is its live screen, which needs the whole app).
+pub fn draw(buf: &mut Buffer, app: &App, body: Rect, kind: &PickerKind, picker: &mut Picker) -> (Option<Position>, Option<Rect>) {
+ // ── machines & devices ── (the same panel, laid out by devices.rs: Add phone's QR code takes
+ // the panel's whole height, and each view draws its own right side)
+ if let PickerKind::Devices(view) = kind { return (crate::devices::draw(buf, app, body, *view, picker), None) }
+ let c = chrome();
+ backdrop(buf, body, c.backdrop);
+ if body.width < 24 || body.height < 8 {
+ put(buf, body.x, body.y, body.width, &format!("{} · resize or Esc", title(app, kind, picker)), c.base);
+ return (None, None);
+ }
+ let r = area(body);
+ fill(buf, r, c.base);
+ picker.screen_area.set(r);
+ let (x, right) = (r.x + 2, r.right().saturating_sub(2));
+ let inner_w = right.saturating_sub(x);
+
+ // Title: where you are, and how to leave.
+ let mut at = x + put(buf, x, r.y + 1, inner_w, &title(app, kind, picker), c.base.add_modifier(Modifier::BOLD));
+ if let Some(section) = picker.theme_in.as_deref() {
+ at += put(buf, at, r.y + 1, right.saturating_sub(at), " › ", c.muted);
+ at += put(buf, at, r.y + 1, right.saturating_sub(at), section_title(section), c.accent);
+ }
+ // What the list says of itself (a count, "searching…"), before the way out.
+ let status = picker.busy.clone().unwrap_or_else(|| picker.status.clone());
+ if !status.is_empty() {
+ let w = (status.width() as u16).min(right.saturating_sub(at + 8));
+ put(buf, right.saturating_sub(w + 6), r.y + 1, w, &status, c.muted);
+ }
+ put(buf, right.saturating_sub(3), r.y + 1, 3, "esc", c.muted);
+
+ // The query: at the top of the menus (as the New Harness chooser has its own); at the bottom
+ // of the launcher's lists, fzf's way, its keys and its count over it (below).
+ let launcher = crate::modal::is_launcher(kind);
+ let qy = if launcher { r.bottom().saturating_sub(2) } else { r.y + 3 };
+ put(buf, x, qy, 2, "›", c.accent);
+ let hint = if launcher { format!("Search {}", title(app, kind, picker).to_lowercase()) } else { picker.placeholder.clone() };
+ let shown = if picker.query.is_empty() { (hint.as_str(), c.muted) } else { (picker.query.as_str(), c.base) };
+ let qw = put(buf, x + 2, qy, inner_w.saturating_sub(2), shown.0, shown.1);
+ picker.prompt_at.set((qy, x + 2));
+ let before: String = picker.query.chars().take(picker.qcursor).collect();
+ let cursor = Position::new((x + 2 + before.width() as u16).min(right), qy);
+
+ if launcher {
+ // After the query: the lists it switches between, the one you are in marked.
+ let here = crate::picker::scope_of(&picker.query);
+ let mut sx = x + 2 + qw + 3;
+ for (ch, name) in [(Some('>'), "commands"), (Some('@'), "machines"), (Some('#'), "projects"), (Some(':'), "models"), (Some('*'), "store"), (Some('?'), "help")] {
+ let text = format!("{} {name}", ch.unwrap_or(' '));
+ if sx + text.width() as u16 > right { break }
+ let on = here == ch;
+ sx += put(buf, sx, qy, right.saturating_sub(sx), &text, if on { c.base.add_modifier(Modifier::BOLD | Modifier::UNDERLINED) } else { c.muted }) + 3;
+ }
+ // Over it: how many rows match of how many (and how many marked), a rule after.
+ let count = format!("{}/{} ({})", picker.visible.len(), picker.rows.len(), picker.marked.len());
+ let cw = put(buf, x, qy - 1, inner_w, &count, c.muted);
+ for cx in x + cw + 1..right { put(buf, cx, qy - 1, 1, "─", c.muted.remove_modifier(Modifier::BOLD)); }
+ // Over that: this list's keys, `key what` · `key what`, the keys bold.
+ let mut kx = x;
+ for (i, (k, what)) in picker.hints.iter().enumerate() {
+ if i > 0 { kx += put(buf, kx, qy - 2, right.saturating_sub(kx), " · ", c.muted); }
+ kx += put(buf, kx, qy - 2, right.saturating_sub(kx), k, c.base.add_modifier(Modifier::BOLD));
+ kx += put(buf, kx, qy - 2, right.saturating_sub(kx), &format!(" {what}"), c.muted);
+ if kx >= right { break }
+ }
+ }
+
+ // The list, and beside it the preview when there is room for both.
+ // (Without a keys row, the list and the preview reach down to the panel's last rows; the
+ // launcher's reach down to its keys.)
+ let (top, bottom) = if launcher { (r.y + 3, r.bottom().saturating_sub(5)) } else { (r.y + 5, r.bottom().saturating_sub(if keyed(kind) { 3 } else { 1 })) };
+ let rows = bottom.saturating_sub(top) as usize;
+ // (Commands need no preview: the list takes the width, a row's hint beside its name. A list
+ // that is the whole answer — output, messages, keys — has none either.)
+ let settings = matches!(kind, PickerKind::Theme);
+ let side = inner_w >= 64 && (settings || (picker.preview && !matches!(kind, PickerKind::Commands)));
- // (A list's preview gets the larger part: a harness's screen, a machine's, a model's facts.)
- let list_w = if !side { inner_w } else if settings { (inner_w * 2 / 5).clamp(28, 40) } else { (inner_w * 2 / 5).clamp(30, 48) };
++ // (A list's preview gets at least half: a harness's screen, a machine's, a model's facts —
++ // the list room for a row's name and what it says, a harness's doing.)
++ let list_w = if !side { inner_w } else if settings { (inner_w * 2 / 5).clamp(28, 40) } else { (inner_w / 2).clamp(30, 56) };
+ list_from(buf, picker, Rect::new(x, top, list_w, rows as u16), &c, !side, launcher);
+ picker.preview_area.set(None);
+ picker.bar.set(None);
+ let mut shown = None;
+ if side {
+ let px = x + list_w + 3;
+ // (The settings' preview is the page's picture, from the query line down; a list's is
+ // beside its rows, under the query and the scopes, which keep the whole width.)
+ let from = if settings { r.y + 3 } else { top };
+ let pr = Rect::new(px, from, right.saturating_sub(px), bottom.saturating_sub(from));
+ if settings {
+ let look = Look::of(app).with(picker.theme_in.as_ref().and(picker.current_id()).as_deref());
+ preview(buf, pr, &look, &c);
+ } else {
+ // A thin rule between the list and its preview, in the panel's muted colour.
+ for y in pr.y..pr.bottom() { put(buf, px - 2, y, 1, "│", c.muted.remove_modifier(Modifier::BOLD)); }
+ picker.preview_area.set(Some((pr, 'r')));
+ shown = Some(pr);
+ }
+ }
+
+ // The footer: what was just said, else — in the menus (Commands, Appearance) — their keys. The
+ // other lists say nothing there: their room is the list's and the preview's.
+ // (The launcher's: in place of its keys, for the moment it is said.)
+ let fy = r.bottom().saturating_sub(if launcher { 4 } else if keyed(kind) { 2 } else { 1 });
+ let flash = picker.flash.as_ref().filter(|(_, at)| at.elapsed().as_secs() < 3).map(|(t, _)| t.clone());
+ let keys = match kind {
+ PickerKind::Commands => Some("↑↓ move enter run type to search esc close"),
+ PickerKind::Theme if picker.theme_in.is_some() => Some("↑↓ move enter apply ← back esc back"),
+ PickerKind::Theme if picker.from_commands => Some("↑↓ move → open type to search esc back"),
+ PickerKind::Theme => Some("↑↓ move → open type to search esc close"),
+ _ => None,
+ };
+ match (flash, keys) {
+ (Some(text), _) => { put(buf, x, fy, inner_w, &" ".repeat(inner_w as usize), c.base); put(buf, x, fy, inner_w, &text, c.accent); }
+ (None, Some(keys)) => { put(buf, x, fy, inner_w, keys, c.muted); }
+ (None, None) => {}
+ }
+ (Some(cursor), shown)
+}
+
+/// The menus, whose footer says their keys (the other lists give that row to their rows).
+fn keyed(kind: &PickerKind) -> bool { matches!(kind, PickerKind::Theme | PickerKind::Commands) }
+
+/// The panel's title: the list's own name (the launcher's for its lists, else what opened it).
+fn title(app: &App, kind: &PickerKind, picker: &Picker) -> String {
+ match kind {
+ PickerKind::Theme => "Appearance".into(),
+ PickerKind::Commands => "Commands".into(),
+ PickerKind::Devices(view) => view.title().into(),
+ k if crate::modal::is_launcher(k) => capital(&crate::modal::launcher_title(app, k).0),
+ _ => capital(&picker.heading.clone().unwrap_or_else(|| picker.title.clone())),
+ }
+}
+
+fn capital(t: &str) -> String { let mut c = t.chars(); c.next().map(|f| f.to_uppercase().chain(c).collect()).unwrap_or_default() }
+
+pub fn section_title(section: &str) -> &'static str {
+ match section {
+ "status" => "Pane titles", "focus" => "Focus",
+ "split" => "Split direction", "layout" => "Layout", "theme" => "Theme",
+ // ── status bar ──
+ "bar" => "Status bar", "boxes" => "Borders",
+ _ => "",
+ }
+}
+
+/// The rows, top-down, the cursor's row marked as the New Harness chooser marks its own.
+pub fn list(buf: &mut Buffer, picker: &mut Picker, r: Rect, c: &Chrome, details: bool) { list_from(buf, picker, r, c, details, false) }
+
+/// [list], [bottom_up]: the first row at the bottom, by the query under it, the rest going up
+/// (fzf's way, for the launcher's lists) — a group's heading over its rows still.
+pub fn list_from(buf: &mut Buffer, picker: &mut Picker, r: Rect, c: &Chrome, details: bool, bottom_up: bool) {
+ picker.list_area.set(r);
+ let mut row_at = Vec::new();
+ let n = r.height as usize;
+ if n == 0 { picker.row_at = row_at; return }
+ if picker.visible.is_empty() {
+ // (A list says what its emptiness means — "no harnesses yet" — where it can.)
+ let empty = if picker.empty.is_empty() || !picker.query.is_empty() { "Nothing matches".to_string() } else { picker.empty.clone() };
+ put(buf, r.x + 2, if bottom_up { r.bottom() - 1 } else { r.y }, r.width.saturating_sub(2), &empty, c.muted);
+ picker.row_at = row_at;
+ return;
+ }
+ // The lines as drawn: each row, and a titled heading (a blank line before it) wherever the
+ // group changes — as opencode's palette groups its commands. The scroll counts lines.
+ let mut lines: Vec<Option<usize>> = Vec::new();
+ let mut titles: Vec<(usize, String)> = Vec::new();
+ let mut last: Option<&str> = None;
+ // (While typing, the best matches come first, untitled — as opencode's search reads.)
+ // (A launcher's scope character alone — `:` — is no search yet: its list keeps its headings.)
+ let grouped = picker.query.is_empty() || (picker.prefixed && crate::picker::scope_of(&picker.query).is_some() && picker.query.trim().chars().count() == 1);
+ if !bottom_up {
+ for vi in 0..picker.visible.len() {
+ let group = picker.rows[picker.visible[vi].0].group.as_deref().filter(|_| grouped);
+ if group.is_some() && group != last {
+ if !lines.is_empty() { lines.push(None) }
+ titles.push((lines.len(), group.unwrap_or_default().to_string()));
+ lines.push(None);
+ }
+ last = group;
+ lines.push(Some(vi));
+ }
+ } else {
+ // Bottom up: a group's rows, then its heading (drawn over them), then a blank.
+ let mut pending: Option<String> = None;
+ for vi in 0..picker.visible.len() {
+ let group = picker.rows[picker.visible[vi].0].group.as_deref().filter(|_| grouped);
+ if group != last {
+ if let Some(title) = pending.take() { titles.push((lines.len(), title)); lines.push(None); lines.push(None) }
+ pending = group.map(str::to_string);
+ }
+ last = group;
+ lines.push(Some(vi));
+ }
+ if let Some(title) = pending { titles.push((lines.len(), title)); lines.push(None) }
+ }
+ let at_line = lines.iter().position(|l| *l == Some(picker.cursor)).unwrap_or(0);
+ // (The cursor's heading comes into view with it.)
+ let top = if !bottom_up && at_line >= 1 && titles.iter().any(|(i, _)| *i + 1 == at_line) { at_line - 1 } else { at_line };
+ if top < picker.scroll { picker.scroll = top }
+ if at_line >= picker.scroll + n { picker.scroll = at_line + 1 - n }
+ picker.scroll = picker.scroll.min(lines.len().saturating_sub(n));
+ for (slot, line) in lines.iter().enumerate().skip(picker.scroll).take(n).map(|(i, l)| (i - picker.scroll, (i, *l))) {
+ let y = if bottom_up { r.bottom() - 1 - slot as u16 } else { r.y + slot as u16 };
+ let (li, Some(vi)) = line else {
+ if let Some((_, title)) = titles.iter().find(|(i, _)| *i == line.0) { put(buf, r.x + 2, y, r.width.saturating_sub(2), title, c.muted.add_modifier(Modifier::BOLD)); }
+ continue;
+ };
+ let _ = li;
+ let row = &picker.rows[picker.visible[vi].0];
+ let here = vi == picker.cursor;
+ let style = if here { c.selected } else { c.base };
+ if here { for x in r.x..r.right() { if let Some(cell) = buf.cell_mut((x, y)) { cell.set_style(style); } } }
+ put(buf, r.x, y, 1, if here { "›" } else { " " }, if here { c.selected } else { c.accent });
+ // Marked with Tab (several at once): a dot beside the pointer.
+ if picker.marked.contains(&row.id) { put(buf, r.x + 1, y, 1, "•", if here { c.selected } else { c.accent }); }
+ let mut at = r.x + 2;
+ for span in &row.lead {
+ let s = if here { style.patch(Style::default().fg(span.style.fg.unwrap_or(Color::Reset))) } else { c.base.patch(span.style) };
+ at += put(buf, at, y, r.right().saturating_sub(at), &span.content, s);
+ }
+ // The right column as the row has it for this width (its short form in a narrow list:
+ // a harness's age, not its project and machine), and never more than a third of the
+ // row — so it can not run off the panel or over the name.
+ let right_text = row.right_at(r.width as usize);
+ let right_w = (right_text.width() as u16).min(r.width / 3);
+ // (The last column is the scroll mark's, with a blank before it.)
+ let end = r.right().saturating_sub(if right_w > 0 { right_w + 3 } else { 2 });
+ // The hint after the name, in a column of its own, where there is room for both.
+ let hint: String = if details { row.detail.iter().map(|s| s.content.as_ref()).collect() } else { String::new() };
+ let hx = at + 28;
+ let with_hint = !hint.is_empty() && hx + 8 < end;
+ at += put(buf, at, y, if with_hint { 26 } else { end.saturating_sub(at) }, &row.label, style);
- if with_hint { put(buf, hx.max(at + 2), y, end - hx.max(at + 2), &hint, if here { style.remove_modifier(Modifier::BOLD) } else { c.muted }); }
++ let quiet = if here { style.remove_modifier(Modifier::BOLD) } else { c.muted };
++ if with_hint { put(buf, hx.max(at + 2), y, end - hx.max(at + 2), &hint, quiet); }
++ else if !details && at + 10 < end {
++ // Beside a preview, what the row says (what a harness is doing, what it did) follows
++ // its name, where it fits.
++ let said: String = row.detail.iter().map(|s| s.content.as_ref()).collect();
++ if !said.is_empty() { put(buf, at, y, end - at, &format!(" · {said}"), quiet); }
++ }
+ if right_w > 0 { put(buf, r.right().saturating_sub(right_w + 2), y, right_w, right_text, if here { style } else { c.muted }); }
+ row_at.push((y, vi));
+ }
+ // (No scrollbar: the list follows the cursor, the wheel scrolls it.)
+ picker.row_at = row_at;
+}
+
+// ── the preview: a small hn with the whole look applied ─────────────────────────────
+
+/// Every setting the panel covers, as the preview draws it.
+#[derive(Clone, Debug)]
+pub struct Look {
+ pub status: String,
+ pub indicators: String,
+ pub lines: String,
+ pub surface: bool,
+ pub split: String,
+ pub layout: String,
+ pub theme: Option<&'static TerminalTheme>,
+ // ── status bar ──
+ /// Where the status bar is (bottom, top, left, right), and box panes.
+ pub bar: String,
+ pub boxes: bool,
+}
+
+impl Look {
+ /// The look as the options hold it now.
+ pub fn of(app: &App) -> Look {
+ let o = &app.options;
+ let get = |k: &str, d: &str| o.get(k, "", None).unwrap_or_else(|| d.to_string());
+ let theme = o.get("@hn-theme", "", None).and_then(|n| TERMINAL_THEMES.iter().find(|t| t.name == n));
+ Look {
+ status: get("pane-border-status", "top"),
+ indicators: get("pane-border-indicators", "colour"),
+ lines: get("pane-border-lines", "single"),
+ surface: o.focus_style() == "surface",
+ split: o.look_orientation().to_string(),
+ layout: get("@hn-layout-preset", "auto"),
+ theme,
+ // ── status bar ──
+ bar: match o.status_bar() { "bottom" if app.status_top => "top".into(), b => b.into() },
+ boxes: o.get("@hn-border", "", None).as_deref() != Some("line"),
+ }
+ }
+
+ /// The look with the row under the cursor (`knob:value`) in effect — what choosing it would do.
+ pub fn with(mut self, row: Option<&str>) -> Look {
+ let Some((knob, value)) = row.and_then(|r| r.split_once(':')) else { return self };
+ match knob {
+ "border_status" => self.status = value.into(),
+ "border_indicators" => self.indicators = value.into(),
+ "border_lines" => self.lines = value.into(),
+ "focus" => self.surface = value == "surface",
+ "layout_orientation" => self.split = value.into(),
+ "layout_preset" => self.layout = value.into(),
+ "theme" => self.theme = TERMINAL_THEMES.iter().find(|t| t.name == value),
+ // ── status bar ──
+ "status_bar" => self.bar = value.into(),
+ "border_style" => self.boxes = value == "box",
+ _ => {}
+ }
+ self
+ }
+}
+
+fn rgb(c: [u8; 3]) -> Color { theme::depth_fit(Color::Rgb(c[0], c[1], c[2])) }
+
+/// hn's own accent on the terminal's own colours (no theme's): its teal, for light or dark.
+fn native_accent() -> Color {
+ let light = crate::term_out::native_terminal_colours().and_then(|(bg, _)| crate::tmuxconf::colour(&bg)).is_some_and(|c| matches!(c, Color::Rgb(r, g, b) if 299 * r as u32 + 587 * g as u32 + 114 * b as u32 > 128_000));
+ if light { Color::Rgb(0, 100, 120) } else { Color::Rgb(95, 215, 230) }
+}
+
+/// The panes a layout makes of [r], the first the active one: tmux's presets with three panes,
+/// `auto` two split the way the split direction says (left|right when it is free to choose here).
+pub fn tiles(r: Rect, layout: &str, split: &str) -> Vec<Rect> {
+ let cols = |r: Rect, n: u16| -> Vec<Rect> {
+ let w = r.width.saturating_sub(n - 1) / n;
+ (0..n).map(|i| { let x = r.x + i * (w + 1); Rect::new(x, r.y, if i + 1 == n { r.right().saturating_sub(x) } else { w }, r.height) }).collect()
+ };
+ let rows = |r: Rect, n: u16| -> Vec<Rect> {
+ let h = r.height.saturating_sub(n - 1) / n;
+ (0..n).map(|i| { let y = r.y + i * (h + 1); Rect::new(r.x, y, r.width, if i + 1 == n { r.bottom().saturating_sub(y) } else { h }) }).collect()
+ };
+ match layout {
+ "even-horizontal" => cols(r, 3),
+ "even-vertical" => rows(r, 3),
+ "main-horizontal" => {
+ let h = (r.height * 3 / 5).max(1);
+ let mut v = vec![Rect::new(r.x, r.y, r.width, h)];
+ v.extend(cols(Rect::new(r.x, r.y + h + 1, r.width, r.height.saturating_sub(h + 1)), 2));
+ v
+ }
+ "main-vertical" => {
+ let w = (r.width * 3 / 5).max(1);
+ let mut v = vec![Rect::new(r.x, r.y, w, r.height)];
+ v.extend(rows(Rect::new(r.x + w + 1, r.y, r.width.saturating_sub(w + 1), r.height), 2));
+ v
+ }
+ "tiled" => {
+ let halves = rows(r, 2);
+ let mut v = cols(halves[0], 2);
+ v.push(halves[1]);
+ v
+ }
+ // (Horizontal is a left|right split, as `smart_dir` splits a wide pane.)
+ _ => if split == "vertical" { rows(r, 2) } else { cols(r, 2) },
+ }
+}
+
+/// A border cell's glyph from the border cells around it — the lines join as tmux's do.
+pub(crate) fn joint(lines: &str, up: bool, down: bool, left: bool, right: bool) -> &'static str {
+ let set: [&str; 11] = match lines {
+ "double" => ["═", "║", "╔", "╗", "╚", "╝", "╠", "╣", "╦", "╩", "╬"],
+ "heavy" => ["━", "┃", "┏", "┓", "┗", "┛", "┣", "┫", "┳", "┻", "╋"],
+ "simple" => ["-", "|", "+", "+", "+", "+", "+", "+", "+", "+", "+"],
+ _ => ["─", "│", "┌", "┐", "└", "┘", "├", "┤", "┬", "┴", "┼"],
+ };
+ match (up, down, left, right) {
+ (true, true, true, true) => set[10],
+ (true, true, false, true) => set[6],
+ (true, true, true, false) => set[7],
+ (false, true, true, true) => set[8],
+ (true, false, true, true) => set[9],
+ (false, true, false, true) => set[2],
+ (false, true, true, false) => set[3],
+ (true, false, false, true) => set[4],
+ (true, false, true, false) => set[5],
+ (true, _, false, false) | (_, true, false, false) => set[1],
+ _ => set[0],
+ }
+}
+
+/// The preview: a label, then a small hn — its panes in the layout, their borders, title rows and
+/// focus, drawn in the theme's colours, with the status line under them.
+pub fn preview(buf: &mut Buffer, r: Rect, look: &Look, c: &Chrome) {
+ if r.width < 16 || r.height < 6 { return }
+ // Everything in it — the status bar and borders too — from the theme it shows.
+ let (pal, accent) = match look.theme {
+ Some(t) => (theme::pane_palette_of(t.background, t.foreground), rgb(theme::theme_accent_rgb(t))),
+ None => (theme::native_pane_palette(), native_accent()),
+ };
+ let (bg, fg) = (pal.surface, pal.foreground);
+ let name = look.theme.map(|t| t.name).unwrap_or("your terminal's colours");
+ let at = r.x + put(buf, r.x, r.y, r.width, "Preview · ", c.muted);
+ put(buf, at, r.y, r.right().saturating_sub(at), name, c.base);
+
+ let screen = Rect::new(r.x, r.y + 2, r.width, r.height.saturating_sub(2).min(18));
+ // ── status bar ──
+ // The status line at the bottom or the top, or the bar down a side.
+ let (body, status_row, side) = match look.bar.as_str() {
+ "top" => (Rect::new(screen.x, screen.y + 1, screen.width, screen.height - 1), Some(screen.y), None),
+ "left" | "right" => {
+ let w = (screen.width / 4).clamp(10, 16);
+ let bar = Rect::new(if look.bar == "left" { screen.x } else { screen.right() - w }, screen.y, w, screen.height);
+ (Rect::new(if look.bar == "left" { screen.x + w } else { screen.x }, screen.y, screen.width - w, screen.height), None, Some(bar))
+ }
+ _ => (Rect::new(screen.x, screen.y, screen.width, screen.height - 1), Some(screen.bottom() - 1), None),
+ };
+ let boxed = look.boxes && !look.surface;
- let canvas = if look.surface { pal.canvas } else { bg };
- for y in body.y..body.bottom() { for x in body.x..body.right() { if let Some(cell) = buf.cell_mut((x, y)) { cell.reset(); cell.set_style(Style::default().bg(canvas)); } } }
++ // Blurred surfaces too sit on the terminal's own background.
++ for y in body.y..body.bottom() { for x in body.x..body.right() { if let Some(cell) = buf.cell_mut((x, y)) { cell.reset(); cell.set_style(Style::default().bg(bg)); } } }
+
+ let panes = tiles(body, &look.layout, &look.split);
+ let names = ["claude", "codex", "shell"];
+ let inside = |x: u16, y: u16| panes.iter().any(|p| x >= p.x && x < p.right() && y >= p.y && y < p.bottom());
+ let border = |x: u16, y: u16| x >= body.x && x < body.right() && y >= body.y && y < body.bottom() && !inside(x, y);
+ let active = panes[0];
+ // Next to the active pane: its borders take the indicator (a colour, arrows, or both).
+ let touches = |x: u16, y: u16| x + 1 >= active.x && x <= active.right() && y + 1 >= active.y && y <= active.bottom();
+ let colour = matches!(look.indicators.as_str(), "colour" | "both");
+ let arrows = matches!(look.indicators.as_str(), "arrows" | "both");
+ if !look.surface && !boxed {
+ for y in body.y..body.bottom() {
+ for x in body.x..body.right() {
+ if !border(x, y) { continue }
+ let g = joint(&look.lines, y > body.y && border(x, y - 1), border(x, y + 1), x > body.x && border(x - 1, y), border(x + 1, y));
+ let style = if colour && touches(x, y) { Style::default().fg(accent).bg(bg) } else { Style::default().fg(pal.border).bg(bg) };
+ buf.set_string(x, y, g, style);
+ }
+ }
+ if arrows {
+ // One arrow on each border beside the active pane, pointing into it.
+ let style = Style::default().fg(accent).bg(bg).add_modifier(Modifier::BOLD);
+ let mid_y = active.y + active.height / 2;
+ let mid_x = active.x + active.width / 2;
+ if border(active.right(), mid_y) { buf.set_string(active.right(), mid_y, "◀", style) }
+ if active.x > body.x && border(active.x - 1, mid_y) { buf.set_string(active.x - 1, mid_y, "▶", style) }
+ if border(mid_x, active.bottom()) { buf.set_string(mid_x, active.bottom(), "▲", style) }
+ }
+ }
+
+ let lines: [&[(&str, bool)]; 3] = [
+ &[("❯ ", true), ("fix the login bug", false)],
+ &[("⠹ ", true), ("Reading src/auth.rs", false)],
+ &[("$ ", true), ("cargo test", false)],
+ ];
+ for (i, p) in panes.iter().enumerate() {
+ let here = i == 0;
+ let (pbg, pfg) = if look.surface && !here { (pal.inactive_surface, pal.inactive_foreground) } else { (bg, fg) };
+ for y in p.y..p.bottom() { for x in p.x..p.right() { if let Some(cell) = buf.cell_mut((x, y)) { cell.reset(); cell.set_style(Style::default().bg(pbg)); } } }
+ let mut content = *p;
+ // ── status bar ──
+ // A box: the focused pane's frame in the accent, the next one's as a harness waiting on
+ // you draws it, the rest quiet; the title in the frame's top or bottom line.
+ if boxed && p.width >= 3 && p.height >= 3 {
+ let frame = Style::default().fg(if here { accent } else if i == 1 { theme::paint(theme::ATTENTION) } else { pal.border }).bg(pbg);
+ let (x1, y1) = (p.right() - 1, p.bottom() - 1);
+ for x in p.x + 1..x1 { buf.set_string(x, p.y, joint(&look.lines, false, false, true, true), frame); buf.set_string(x, y1, joint(&look.lines, false, false, true, true), frame) }
+ for y in p.y + 1..y1 { buf.set_string(p.x, y, joint(&look.lines, true, true, false, false), frame); buf.set_string(x1, y, joint(&look.lines, true, true, false, false), frame) }
+ for (x, y, g) in [(p.x, p.y, joint(&look.lines, false, true, false, true)), (x1, p.y, joint(&look.lines, false, true, true, false)), (p.x, y1, joint(&look.lines, true, false, false, true)), (x1, y1, joint(&look.lines, true, false, true, false))] { buf.set_string(x, y, g, frame) }
+ if look.status != "off" {
+ let ty = if look.status == "bottom" { y1 } else { p.y };
+ let ls = if here { frame.add_modifier(Modifier::BOLD) } else if i == 1 { frame } else { Style::default().fg(pfg).bg(pbg) };
+ put(buf, p.x + 1, ty, p.width.saturating_sub(2), &format!(" {} {} ", i + 1, names[i]), ls);
+ }
+ content = Rect::new(p.x, p.y + 1, p.width, p.height - 2);
+ } else if look.status != "off" && p.height >= 3 {
+ // The title row, above or below the pane, as pane-border-status puts it.
+ let ty = if look.status == "bottom" { p.bottom() - 1 } else { p.y };
+ let rule = if look.surface { " " } else { joint(&look.lines, false, false, true, true) };
+ let tstyle = if colour && here { Style::default().fg(accent).bg(pbg) } else { Style::default().fg(pal.border).bg(pbg) };
+ for x in p.x..p.right() { buf.set_string(x, ty, rule, tstyle) }
+ let label = format!(" {} {} ", i + 1, names[i]);
+ let ls = if here { Style::default().fg(accent).bg(pbg).add_modifier(Modifier::BOLD) } else { Style::default().fg(pfg).bg(pbg) };
+ put(buf, p.x + 1, ty, p.width.saturating_sub(2), &label, ls);
+ content = if look.status == "bottom" { Rect::new(p.x, p.y, p.width, p.height - 1) } else { Rect::new(p.x, p.y + 1, p.width, p.height - 1) };
+ }
+ let inner = Rect::new(content.x + 1, content.y, content.width.saturating_sub(2), content.height);
+ for (row, segs) in lines.iter().enumerate() {
+ let y = inner.y + row as u16;
+ if y >= inner.bottom() { break }
+ let mut x = inner.x;
+ for (text, lead) in segs.iter() {
+ let s = Style::default().fg(if *lead { accent } else { pfg }).bg(pbg);
+ x += put(buf, x, y, inner.right().saturating_sub(x), text, s);
+ }
+ }
+ // The theme's sixteen colours, in the first pane where it has room.
+ if let (Some(t), true) = (look.theme, here) {
+ let y = inner.y + lines.len() as u16 + 1;
+ if y < inner.bottom() && inner.width >= 8 {
+ for (k, col) in t.palette.iter().take((inner.width as usize / 2).min(16)).enumerate() {
+ buf.set_string(inner.x + k as u16 * 2, y, "██", Style::default().fg(rgb(*col)).bg(pbg));
+ }
+ }
+ }
+ }
+
+ // The status line, as hn's own sits under the panes (or over them).
+ if let Some(status_row) = status_row {
+ let sstyle = Style::default().fg(pal.status_foreground).bg(pal.status);
+ for x in screen.x..screen.right() { buf.set_string(x, status_row, " ", sstyle) }
+ let mut x = screen.x + 1;
+ for (i, n) in names.iter().take(panes.len()).enumerate() {
+ let s = if i == 0 { sstyle.fg(accent).add_modifier(Modifier::BOLD) } else { sstyle };
+ x += put(buf, x, status_row, screen.right().saturating_sub(x), &format!("{}:{}{} ", i, n, if i == 0 { "*" } else { "" }), s);
+ }
+ put(buf, screen.right().saturating_sub(7), status_row, 6, "studio", sstyle);
+ }
+ // ── status bar ──
+ if let Some(bar) = side { preview_bar(buf, bar, look.bar == "left", &pal, accent, &names[..panes.len().min(2)]) }
+}
+
+/// The status bar down a side, small: the windows, the current one with its panes under it (the
+/// first focused, each with its repo), a rule, the machine with its window, and the separator
+/// facing the panes.
+fn preview_bar(buf: &mut Buffer, bar: Rect, left: bool, pal: &theme::PanePalette, accent: Color, names: &[&str]) {
+ let (bg, fg) = (pal.surface, pal.foreground);
+ for y in bar.y..bar.bottom() { for x in bar.x..bar.right() { if let Some(cell) = buf.cell_mut((x, y)) { cell.reset(); cell.set_style(Style::default().bg(bg)); } } }
+ let sx = if left { bar.right() - 1 } else { bar.x };
+ for y in bar.y..bar.bottom() { buf.set_string(sx, y, "│", Style::default().fg(pal.border).bg(bg)) }
+ let x = if left { bar.x } else { bar.x + 1 };
+ let w = bar.width - 1;
+ let row = theme::depth_fit(mix(bg, fg, 12));
+ let header = Style::default().fg(pal.muted).bg(bg).add_modifier(Modifier::BOLD);
+ let mut y = bar.y;
+ let line = |buf: &mut Buffer, y: &mut u16, spans: &[(&str, Style)], fill: Option<Color>| {
+ if *y >= bar.bottom() { return }
+ if let Some(f) = fill { for cx in x..x + w { buf.set_string(cx, *y, " ", Style::default().bg(f)) } }
+ let mut at = x;
+ for (t, s) in spans { let s = match fill { Some(f) => s.bg(f), None => *s }; at += put(buf, at, *y, (x + w).saturating_sub(at), t, s) }
+ *y += 1;
+ };
+ let dim = Style::default().fg(pal.muted);
+ // (The marks the bar gives: the harnesses' own — a spinner working, `?` waiting, `·` idle — and
+ // `✓` for a connected machine; no round ones.)
+ line(buf, &mut y, &[(" ", header), ("✓", Style::default().fg(theme::paint(theme::ONLINE))), (" studio", header)], None);
+ y += 1;
+ let count = format!(" {}", names.len());
+ line(buf, &mut y, &[(" ", header), ("?", Style::default().fg(theme::paint(theme::ATTENTION))), (" 0:claude", Style::default().fg(fg).add_modifier(Modifier::BOLD)), (&count, dim)], Some(row));
+ for (i, n) in names.iter().enumerate() {
+ let (here, last) = (i == 0, i + 1 == names.len());
+ let fill = here.then_some(row);
+ let (glyph, gc) = if here { (theme::spinner(0), theme::paint(theme::ACCENT_SOFT)) } else { ("?", theme::paint(theme::ATTENTION)) };
+ let name = if here { Style::default().fg(fg).add_modifier(Modifier::BOLD) } else { Style::default().fg(pal.inactive_foreground) };
+ line(buf, &mut y, &[(if last { " └─ " } else { " ├─ " }, dim), (glyph, Style::default().fg(gc)), (" ", name), (n, name)], fill);
+ line(buf, &mut y, &[(if last { " " } else { " │ " }, dim), ("autonomous-harness · main", Style::default().fg(if here { accent } else { pal.muted }))], fill);
+ }
+ line(buf, &mut y, &[(" ", header), ("·", Style::default().fg(pal.muted)), (" 1:ops", Style::default().fg(pal.inactive_foreground))], None);
+ let rule = "─".repeat(w as usize);
+ line(buf, &mut y, &[(&rule, Style::default().fg(pal.border))], None);
+ line(buf, &mut y, &[(" machines", header)], None);
+ y += 1;
+ line(buf, &mut y, &[(" ", header), ("✓", Style::default().fg(theme::paint(theme::ONLINE))), (" studio", Style::default().fg(fg).add_modifier(Modifier::BOLD))], None);
+ line(buf, &mut y, &[(" └─ ", Style::default().fg(pal.muted)), ("?", Style::default().fg(theme::paint(theme::ATTENTION))), (" 0:claude", Style::default().fg(fg).add_modifier(Modifier::BOLD))], Some(row));
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::modal;
+
+ fn app(size: (u16, u16)) -> App {
+ let (sink, _) = tokio::sync::mpsc::unbounded_channel();
+ let mut app = App::new(19789, sink, size);
+ app.fleet.local_id = "local".into();
+ app.fleet.machines.push(crate::fleet::Machine { id: "local".into(), name: "studio".into(), local: true, status: "online".into(), reach: crate::fleet::Reach::Ready });
+ app
+ }
+
+ fn text(buf: &Buffer) -> String {
+ let a = buf.area;
+ (a.y..a.bottom()).map(|y| (a.x..a.right()).map(|x| buf[(x, y)].symbol().to_string()).collect::<String>()).collect::<Vec<_>>().join("\n")
+ }
+
+ fn open(app: &App, section: Option<&str>) -> Picker {
+ let mut p = Picker::new("t", "Search settings");
+ p.keep_order = true;
+ match section {
+ Some(s) => { p.theme_in = Some(s.into()); p.set_rows(modal::theme_options(app, s)) }
+ None => p.set_rows(modal::theme_sections(app)),
+ }
+ p
+ }
+
+ /// The panel stays where it is, the same size, whether it shows the sections or one section's
+ /// options — and draws at every size without a panic.
+ #[test]
+ fn the_panel_does_not_move_when_a_section_opens() {
+ let app = app((150, 42));
+ let body = Rect::new(0, 0, 150, 41);
+ let mut a = open(&app, None);
+ let mut b = open(&app, Some("status"));
+ let mut buf = Buffer::empty(body);
+ draw(&mut buf, &app, body, &PickerKind::Theme, &mut a);
+ let mut buf2 = Buffer::empty(body);
+ draw(&mut buf2, &app, body, &PickerKind::Theme, &mut b);
+ assert_eq!(a.screen_area.get(), b.screen_area.get());
+ assert_eq!(a.list_area.get(), b.list_area.get());
+ for w in [10, 24, 40, 80, 150] { for h in [3, 8, 12, 24, 42] {
+ let r = Rect::new(0, 0, w, h);
+ for section in [None, Some("theme"), Some("layout")] {
+ let mut p = open(&app, section);
+ draw(&mut Buffer::empty(r), &app, r, &PickerKind::Theme, &mut p);
+ }
+ }}
+ }
+
+ /// Inside a section its options are listed, and the panel has no border line around it.
+ #[test]
+ fn a_section_lists_its_options_without_a_border() {
+ let app = app((150, 42));
+ let body = Rect::new(0, 0, 150, 41);
+ let mut p = open(&app, Some("status"));
+ let mut buf = Buffer::empty(body);
+ draw(&mut buf, &app, body, &PickerKind::Theme, &mut p);
+ let s = text(&buf);
+ for v in ["off", "top", "bottom"] { assert!(s.contains(v), "{v} missing:\n{s}") }
+ assert!(s.contains("Appearance") && s.contains("Pane titles"));
+ let r = p.screen_area.get();
+ for x in r.x..r.right() { assert!(!["─", "╭", "╮", "┌"].contains(&buf[(x, r.y)].symbol()), "a border on the panel's top row") }
+ }
+
+ /// The preview shows every section at once, and a hovered option changes only its own part.
+ #[test]
+ fn the_preview_is_the_whole_look_and_follows_the_cursor() {
+ let app = app((150, 42));
+ let look = Look::of(&app);
+ assert_eq!(look.clone().with(Some("border_lines:double")).lines, "double");
+ assert_eq!(look.clone().with(Some("border_lines:double")).status, look.status);
+ assert_eq!(look.clone().with(Some("layout_preset:tiled")).layout, "tiled");
+ assert!(look.clone().with(Some("theme:Adwaita")).theme.is_some());
+ let r = Rect::new(0, 0, 60, 24);
+ let mut buf = Buffer::empty(r);
+ preview(&mut buf, r, &look.clone().with(Some("border_lines:double")), &chrome());
+ let s = text(&buf);
+ assert!(s.contains('║') || s.contains('═'), "double lines drawn:\n{s}");
+ assert!(s.contains("claude") && s.contains("codex"), "the status line names the windows:\n{s}");
+ let mut buf = Buffer::empty(r);
+ preview(&mut buf, r, &look.clone().with(Some("border_status:top")), &chrome());
+ assert!(text(&buf).contains("1 claude"), "title rows drawn");
+ }
+
+ /// The panel takes the theme's colours: two themes, two panels; a light theme a light panel.
+ #[test]
+ fn the_panel_follows_the_theme() {
+ let theme = |n: &str| TERMINAL_THEMES.iter().find(|t| t.name == n).unwrap();
+ let (dark, light) = (theme("Atom One Dark"), theme("Adwaita"));
+ let a = chrome_for(theme::pane_palette_of(dark.background, dark.foreground));
+ let b = chrome_for(theme::pane_palette_of(light.background, light.foreground));
+ assert_ne!(a.base.bg, b.base.bg);
+ let lum = |s: Style| match s.bg { Some(Color::Rgb(r, g, b)) => 299 * r as u32 + 587 * g as u32 + 114 * b as u32, _ => 0 };
+ assert!(lum(b.base) > lum(a.base), "a light theme gives a light panel");
+ assert_ne!(a.base.bg, a.backdrop.bg, "the panel stands out from its backdrop");
+ assert_ne!(a.base.bg, a.selected.bg, "the cursor's row stands out");
+ }
+
+ #[test]
+ fn every_layout_tiles_the_screen_without_overlap() {
+ let r = Rect::new(0, 0, 50, 16);
+ for layout in ["auto", "even-horizontal", "even-vertical", "main-horizontal", "main-vertical", "tiled"] {
+ let t = tiles(r, layout, "auto");
+ assert!(t.len() >= 2, "{layout}");
+ for (i, a) in t.iter().enumerate() { for b in &t[i + 1..] { assert!(a.intersection(*b).area() == 0, "{layout} overlaps") } }
+ }
+ assert!(tiles(r, "auto", "vertical")[1].y > 0, "vertical stacks");
+ assert!(tiles(r, "auto", "horizontal")[1].x > 0, "horizontal is left|right");
+ }
+
+ // ── status bar ──
+
+ /// The preview draws where the status bar goes — the line at the bottom or top, or the bar
+ /// down a side: the windows with the current one's panes and their repos, then the machines —
+ /// and the panes as boxes: the focused one's frame in the accent, one waiting on you in the
+ /// attention colour.
+ #[test]
+ fn the_preview_draws_the_status_bar_where_it_goes_and_the_boxes_in_their_colours() {
+ let app = app((150, 42));
+ let look = Look::of(&app);
+ assert_eq!((look.bar.as_str(), look.boxes), ("bottom", true));
+ let r = Rect::new(0, 0, 64, 20);
+ let draw = |look: &Look| { let mut buf = Buffer::empty(r); preview(&mut buf, r, look, &chrome()); buf };
+ let row = |buf: &Buffer, y: u16| (0..r.width).map(|x| buf[(x, y)].symbol().to_string()).collect::<String>();
+ // (The preview's screen: rows 2 to 19.)
+ let bottom = draw(&look);
+ assert!(row(&bottom, 19).contains("0:claude*"), "{}", text(&bottom));
+ let top = draw(&look.clone().with(Some("status_bar:top")));
+ assert!(row(&top, 2).contains("0:claude*") && !row(&top, 19).contains("0:claude*"), "{}", text(&top));
+ let left = draw(&look.clone().with(Some("status_bar:left")));
+ let s = text(&left);
+ assert!(row(&left, 2).starts_with(" ✓ studio") && row(&left, 4).starts_with(" ? 0:claude 2"), "{s}");
+ assert!(row(&left, 5).starts_with(" ├─ ") && row(&left, 5).contains(" claude") && row(&left, 6).starts_with(" │ autonom") && row(&left, 7).starts_with(" └─ ? codex"), "{s}");
+ assert!(row(&left, 9).starts_with(" · 1:ops") && s.contains(" machines") && s.contains("└─ ? 0:claude"), "{s}");
+ assert!(!s.contains('●') && !s.contains('○'), "no round marks:\n{s}");
+ assert_eq!(left[(15, 2)].symbol(), "│", "the separator faces the panes:\n{s}");
+ // No tabs over the panes: the window starts at the screen's first row, beside the bar.
+ assert_eq!(left[(16, 2)].symbol(), "┌", "{s}");
+ let right = draw(&look.clone().with(Some("status_bar:right")));
+ assert_eq!(right[(64 - 16, 5)].symbol(), "│");
+ // Boxes: each pane its own frame; the focused one's in the accent, the next the attention colour.
+ // (The accent as this draw had it: the current window's name on the status line.)
+ let accent = bottom[(1, 19)].fg;
+ let panes = tiles(Rect::new(0, 2, 64, 17), &look.layout, &look.split);
+ assert_eq!(bottom[(panes[0].x, panes[0].y)].symbol(), "┌");
+ assert_eq!(bottom[(panes[1].x, panes[1].y)].symbol(), "┌");
+ assert_eq!(bottom[(panes[0].x, panes[0].y)].fg, accent);
+ assert_ne!(accent, bottom[(panes[1].x, panes[1].y)].fg);
+ assert_eq!(bottom[(panes[1].x, panes[1].y)].fg, theme::paint(theme::ATTENTION));
+ let line = draw(&look.clone().with(Some("border_style:line")));
+ assert_ne!(line[(panes[1].x, panes[1].y)].symbol(), "┌", "tmux's shared lines");
+ }
+}
diff --cc tui/src/ui.rs
index 77671c124,b219ef4a0..598848fda
--- a/tui/src/ui.rs
+++ b/tui/src/ui.rs
@@@ -267,8 -252,8 +267,8 @@@ fn window(buf: &mut Buffer, app: &mut A
let (a, w) = (app.style_of("window-active-style", app.active, Some(*id)), app.style_of("window-style", app.active, Some(*id)));
let window = if active { (a.fg.or(w.fg), a.bg.or(w.bg)) } else { (w.fg, w.bg) };
if surfaces {
- let f = crate::pane_frame::frame(*rect, app.window_area(app.tab()), app.pane_status(app.tab()));
+ let f = crate::pane_frame::frame(*rect, app.window_area(app.tab()), app.box_inner(app.tab()), app.pane_status(app.tab()));
- // A single or zoomed pane keeps the same surface and surrounding canvas.
+ // Single and zoomed panes also sit directly on the terminal background.
buf.set_style(f.surface, Style::default().fg(window.0.unwrap_or(Color::Reset)).bg(window.1.unwrap_or(Color::Reset)));
}
// choose-tree's tree, over the pane.
@@@ -542,23 -469,6 +543,24 @@@ fn empty_window(buf: &mut Buffer, app:
let x = if index < centered { area.x + area.width.saturating_sub(w) / 2 } else { left };
buf.set_line(x, y, line, area.width.saturating_sub(x - area.x));
}
+ themed_home(buf, area);
+}
+
+/// With a theme chosen (Settings → Theme), the home screen stands on the theme's background where
+/// the terminal's showed — as the panes the daemon paints and the status line already do. (Its
+/// text is the theme's already: `fg` dims the theme's own foreground.) Without one, as the
+/// terminal has it.
+fn themed_home(buf: &mut Buffer, area: Rect) {
+ if !crate::term_out::theme_chosen() || theme::no_color() { return }
- let pal = theme::pane_palette();
++ // The theme's own background (a pane's surface is lifted off it).
++ let (bg, fg, _) = theme::palette();
+ for y in area.y..area.bottom() {
+ for x in area.x..area.right() {
+ let Some(c) = buf.cell_mut((x, y)) else { continue };
- if matches!(c.bg, Color::Reset) { c.bg = theme::depth_fit(pal.surface) }
- if matches!(c.fg, Color::Reset) { c.fg = theme::depth_fit(pal.foreground) }
++ if matches!(c.bg, Color::Reset) { c.bg = theme::depth_fit(bg) }
++ if matches!(c.fg, Color::Reset) { c.fg = theme::depth_fit(fg) }
+ }
+ }
}
diff --cc tui/tests/new-harness.py
index 14e7a99bf,13d4f8fdf..9a025fc53
--- a/tui/tests/new-harness.py
+++ b/tui/tests/new-harness.py
@@@ -84,10 -84,10 +84,13 @@@ def click(x, y)
raw = f'\x1b[<0;{x+1};{y+1}{suffix}'.encode()
tmux('send-keys', '-H', '-t', 'test', *[f'{b:02x}' for b in raw])
settle_ui()
++def field_at(label):
++ # A field's label: after a space, the pointer or an edge (the form is a borderless panel).
++ return r'(?<![^\s│›])(' + label + r') {2,}'
def field(label):
def find():
for y, line in enumerate(screen().splitlines()):
-- m = re.search(r'│[ ›]*(' + re.escape(label) + r') {2,}', line)
++ m = re.search(field_at(re.escape(label)), line)
if m: return m.start(1), y
wait(find, f'field {label}')
click(*find())
@@@ -129,9 -139,9 +142,11 @@@ try
before = create_count()
input_before = len(state('reconnect')['inputs'])
keys('Right'); assert create_count() == before, 'Right on New Harness must not launch'
-- keys('Down'); shows('Search agents and harnesses')
-- assert 'Blender' in screen(), 'the agent chooser appears while moving over Agent'
-- keys('Tab'); snapshot('new-harness-agent')
++ # The chooser opens in the form's place (the panel stays put), once you go into it.
++ keys('Down'); assert 'Search agents and harnesses' not in screen(), 'moving over Agent keeps the form'
++ keys('Tab'); shows('Search agents and harnesses')
++ assert 'Blender' in screen(), 'the agent chooser lists the harnesses'
++ snapshot('new-harness-agent')
type_text('codex'); keys('Escape')
shows('Options'); field('Agent'); type_text('codex'); keys('Enter')
field('Project'); shows('Clone Repository'); snapshot('new-harness-project')
@@@ -142,7 -152,7 +157,7 @@@
field('Project'); type_text('new folder'); keys('Enter'); shows('Choose a machine'); keys('Enter'); shows('Folder name')
type_text('fail-once'); keys('Enter'); shows('New Folder: fail-once')
field('Options'); shows('Approvals'); shows('Model'); shows('Profile')
-- assert not re.search(r'│[ ›]*Machine {2,}', screen()), 'Machine belongs in Project, not Options'
++ assert not re.search(field_at('Machine'), screen()), 'Machine belongs in Project, not Options'
choose_field('Approvals', 'read only'); shows('Read only')
snapshot('new-harness-options')
keys('Enter', 'Enter'); shows('Fixture launch failure')
@@@ -181,14 -191,16 +196,17 @@@
assert 'codexHome' not in request, request
print('PASS New Harness: machine-scoped profiles and explicit model routes', flush=True)
-- new_form(); choose_field('Agent', 'Blender'); shows('Choose a coding agent'); type_text('codex'); keys('Enter'); shows('Blender · Codex')
++ # (Blender asks for its coding agent next, in the form's place.)
++ new_form(); field('Agent'); type_text('Blender'); keys('Enter'); shows('Choose a coding agent'); type_text('codex'); keys('Enter'); shows('Blender · Codex')
submit(before + 6)
assert state()['created'][-1]['dsh'] == 'example/blender'
new_form(); choose_field('Harness', 'Terminal'); field('Options')
-- assert not re.search(r'│[ ›]*(Model|Approvals|Profile) {2,}', screen()), 'Terminal omits irrelevant settings'
++ assert not re.search(field_at('Model|Approvals|Profile'), screen()), 'Terminal omits irrelevant settings'
# Return focus to the action without accepting any of the disabled Git rows.
+ before_terminal = placement()
field('New Harness')
wait(lambda: create_count() == before + 7 and 'Options' not in screen(), 'terminal launch')
+ placed_in_current_window(before_terminal)
request = state()['created'][-1]
assert request['engine'] == 'terminal' and request.get('permissionMode') is None, request
assert not any(k in request for k in ('dsh', 'prompt', 'gridModel', 'gitSource', 'codexHome')), request
diff --cc tui/tests/pane-ui.py
index 8a12c2022,0911ad3ab..43aba6b65
--- a/tui/tests/pane-ui.py
+++ b/tui/tests/pane-ui.py
@@@ -31,7 -31,8 +31,10 @@@ ENV.update(HOME=str(BASE), HN_TMPDIR=st
TERM='xterm-256color', COLORTERM='truecolor', SHELL='/bin/sh', HARNESS_TUI_DESK='sync',
HARNESS_TUI_NOTIFY='off', HN_DESKTOP='off', MOCK_DEMO='1', MOCK_RECONNECT='1', MOCK_USAGE='100')
CONF = BASE / 'tmux.conf'
- CONF.write_text('set -g automatic-rename off\nset -g status-right " #{usage_remaining_mark} #{s/ / /:fleet} #{pane_machine}:#{b:pane_current_path} 20:41 "\n')
++# Box panes are the default; this suite covers the blurred surfaces (`@hn-look panes`).
+ CONF.write_text('set -g automatic-rename off\n'
++ 'set -g @hn-look panes\n'
+ 'set -g status-right \' #{usage_remaining_mark} #{s/ / /:fleet} "#{=/21/…:local_machine}" 20:41 \'\n')
OUTPUT = Path(os.environ['HN_PANE_UI_OUTPUT']) if os.environ.get('HN_PANE_UI_OUTPUT') else None
if OUTPUT:
OUTPUT.mkdir(parents=True, exist_ok=True)
@@@ -117,12 -118,12 +120,13 @@@ def background(hex_value)
tmux('send-keys', '-H', '-t', 'test', *[f'{b:02x}' for b in raw])
++# A surface is the program's cells and one cell around them, its title in the top one: the
++# space between two panes is the one cell tmux keeps between them.
def pane_edge_background(pane, colour):
x, y, w, h = map(int, value('#{pane_left} #{pane_top} #{pane_width} #{pane_height}', pane).split())
-- points = ((x - 1, y - 2), (x + w, y - 2), (x - 1, y + h),
-- (x + w, y + h), (x - 1, y - 1), (x + w, y + h // 2),
-- (x - 2, y - 3), (x + w + 1, y - 3), (x - 2, y + h + 1),
-- (x + w + 1, y + h + 1), (x + w // 2, y - 3), (x - 2, y + h // 2))
++ points = ((x - 1, y - 1), (x + w, y - 1), (x - 1, y + h),
++ (x + w, y + h), (x + w // 2, y - 1), (x + w, y + h // 2),
++ (x - 1, y + h // 2), (x + w // 2, y + h))
return all(background_at(col, row) == colour for col, row in points)
@@@ -135,7 -136,7 +139,7 @@@ def pane_outline(pane, kind=None)
x, y, w, h = map(int, value('#{pane_left} #{pane_top} #{pane_width} #{pane_height}', pane).split())
screen = tmux('capture-pane', '-p', '-t', 'test').splitlines()
styles = {'thin': '┌┐└┘', 'heavy': '┏┓┗┛', 'double': '╔╗╚╝'}
-- points = ((x - 2, y - 3), (x + w + 1, y - 3), (x - 2, y + h + 1), (x + w + 1, y + h + 1))
++ points = ((x - 1, y - 1), (x + w, y - 1), (x - 1, y + h), (x + w, y + h))
return any(all(0 <= row < len(screen) and 0 <= col < len(screen[row]) and screen[row][col] == glyph
for (col, row), glyph in zip(points, glyphs))
for glyphs in ([styles[kind]] if kind else styles.values()))
@@@ -143,7 -144,7 +147,7 @@@
def pane_title_color(pane, foreground=True):
x, y = map(int, value('#{pane_left} #{pane_top}', pane).split())
-- return color_at(x - 1, y - 2, foreground=foreground)
++ return color_at(x, y - 1, foreground=foreground)
def snapshot(name):
@@@ -189,12 -190,12 +193,12 @@@ try
active_bg = hn('show', '-gwv', 'window-active-style').split('bg=')[1]
inactive_bg = hn('show', '-gwv', 'window-style').split('bg=')[1]
assert active_bg != inactive_bg
- assert active_bg == '#000000' and inactive_bg == '#404040'
+ assert active_bg == '#181818' and inactive_bg == '#404040'
wait(lambda: not any(pane_outline(p) for p in (first, second, third)), 'pane backgrounds without outlines')
wait(lambda: pane_background(first) == active_bg and pane_background(second) == inactive_bg, 'whole-pane focus contrast')
- assert background_at(149, 0) == '#202020', 'dark backdrop surrounds the pane cards'
- assert background_at(149, 0) == 'default', 'outer margins use the native terminal background'
++ assert background_at(149, 0) == inactive_bg, 'panes reach the window edges: no outer margin'
wait(lambda: pane_edge_background(first, active_bg), 'focused background fills through the pane edges')
- assert background_at(49, 20) == background_at(99, 20) == '#202020', 'dark gaps separate pane backgrounds'
+ assert background_at(49, 20) == background_at(99, 20) == 'default', 'pane gaps use the native terminal background'
assert pane_edge_background(second, inactive_bg)
tab = value(hn('show', '-gwv', 'window-status-current-format'))
label = value('#{window_index}:#{window_short_name}')
@@@ -285,7 -293,7 +296,7 @@@
hn('select-pane', '-t', second, '-T', long_title)
x, y, w = map(int, value('#{pane_left} #{pane_top} #{pane_width}', second).split())
def waiting_heading():
-- return tmux('capture-pane', '-p', '-t', 'test').splitlines()[y - 2][x:x + w].strip()
++ return tmux('capture-pane', '-p', '-t', 'test').splitlines()[y - 1][x:x + w].strip()
wait(lambda: waiting_heading().endswith('(2) ?'), 'long pane names retain their suffix and waiting indicator')
assert '…' in waiting_heading()
assert value('#{pane_title}', second) == long_title, 'raw pane title must remain unchanged'
@@@ -302,20 -310,24 +313,24 @@@
wait(lambda: value('#{pane_id}') == third, 'second C-b Right')
keys('C-b', 'Right')
wait(lambda: value('#{pane_id}') == first, 'directional wrap')
- keys('C-b', 'z')
- wait(lambda: value('#{window_zoomed_flag}') == '1', 'zoom')
- branch_context = value('#{pane_where}')
- assert '⑂ ' + value('#{pane_branch}') in branch_context, branch_context
- assert 'git:(' not in branch_context
- wait(lambda: not pane_outline(first) and background_at(1, 1) == active_bg
- and background_at(0, 0) == background_at(149, 40) == '#202020',
- 'zoomed pane keeps its focused surface inside the canvas')
- wait(lambda: background_at(0, 41) == normal_bg, 'status bar keeps its own color after transient completion notices')
- x, y, w = map(int, value('#{pane_left} #{pane_top} #{pane_width}', first).split())
- wait(lambda: tmux('capture-pane', '-p', '-t', 'test').splitlines()[y - 2][x:x + w].rstrip().endswith(branch_context), 'branch and PR align to the right edge')
- snapshot('panes-zoomed')
- keys('C-b', 'z')
- wait(lambda: value('#{window_zoomed_flag}') == '0', 'unzoom')
+ for target in (first, third):
+ hn('select-pane', '-t', target)
+ keys('C-b', 'z')
+ wait(lambda: value('#{window_zoomed_flag}') == '1', 'zoom')
+ branch_context = value('#{pane_where}')
+ assert branch_context.startswith(value('#{pane_machine}:#{pane_project}') + ' '), branch_context
+ assert '⎇ ' + value('#{pane_branch}') in branch_context, branch_context
+ assert 'git:(' not in branch_context
+ wait(lambda: not pane_outline(target) and background_at(1, 1) == active_bg
- and background_at(0, 0) == background_at(149, 40) == 'default',
- 'zoomed pane sits directly on the terminal background')
++ and background_at(0, 0) == background_at(149, 40) == active_bg,
++ 'a zoomed pane fills the window, to its edges')
+ wait(lambda: background_at(0, 41) == normal_bg, 'status bar keeps its own color after transient completion notices')
+ x, y, w = map(int, value('#{pane_left} #{pane_top} #{pane_width}', target).split())
- wait(lambda: tmux('capture-pane', '-p', '-t', 'test').splitlines()[y - 2][x:x + w].rstrip().endswith(branch_context), 'machine, project, branch and PR align to the right edge')
++ wait(lambda: tmux('capture-pane', '-p', '-t', 'test').splitlines()[y - 1][x:x + w].rstrip().endswith(branch_context), 'machine, project, branch and PR align to the right edge')
+ snapshot('panes-zoomed' if target == first else 'panes-remote-zoomed')
+ keys('C-b', 'z')
+ wait(lambda: value('#{window_zoomed_flag}') == '0', 'unzoom')
+ hn('select-pane', '-t', first)
assert value('#{window_layout}') == original
print('PASS pane UI: directional keys, wrap, zoom preserve layout structure', flush=True)
@@@ -327,7 -339,7 +342,7 @@@
hn('set', '-g', '@hn-look', 'panes')
assert value('#{window_layout}') == original
x, y, w, h = map(int, value('#{pane_left} #{pane_top} #{pane_width} #{pane_height}', first).split())
-- assert x > 0 and y > 1 and w > 0 and h > 0
++ assert x > 0 and y > 0 and w > 0 and h > 0
hn('send-keys', '-t', first, '-l', '\x1b[?1000h\x1b[?1006h')
wait(lambda: value('#{mouse_sgr_flag}', first) == '1', 'program mouse mode')
before = len(api()['inputs'])
@@@ -339,8 -351,8 +354,8 @@@
# Titles and padding focus the pane without sending a click to its program.
before = len(api()['inputs'])
second_x, second_y = map(int, value('#{pane_left} #{pane_top}', second).split())
-- mouse(0, second_x, second_y - 2)
-- mouse(0, second_x, second_y - 2, release=True)
++ mouse(0, second_x, second_y - 1)
++ mouse(0, second_x, second_y - 1, release=True)
wait(lambda: value('#{pane_id}') == second, 'click the pane header')
wait(lambda: pane_background(second) == active_bg and pane_background(first) == inactive_bg, 'mouse focus moves pane contrast')
wait(lambda: not pane_outline(second) and not pane_outline(first), 'mouse focus leaves no outlines')
@@@ -419,9 -431,10 +434,10 @@@
layout_before_theme = value('#{window_layout}')
before = len(api()['inputs'])
background('#f7f7f7')
- wait(lambda: hn('show', '-gwv', 'window-active-style') == 'fg=#1a1a1a,bg=#f7f7f7', 'light surface defaults')
- wait(lambda: pane_background(first) == '#f7f7f7' and pane_background(second) == '#e5e5e5', 'light focus contrast')
- wait(lambda: pane_edge_background(first, '#f7f7f7') and pane_title_color(first, foreground=False) == '#f7f7f7', 'light surface fills the focused pane through its padding')
+ wait(lambda: hn('show', '-gwv', 'window-active-style') == 'fg=#1a1a1a,bg=#eeeeee', 'light surface defaults')
+ wait(lambda: pane_background(first) == '#eeeeee' and pane_background(second) == '#e5e5e5', 'light focus contrast')
+ wait(lambda: pane_edge_background(first, '#eeeeee') and pane_title_color(first, foreground=False) == '#eeeeee', 'light surface fills the focused pane through its padding')
- assert background_at(149, 0) == 'default', 'light theme also keeps the native terminal background'
++ assert background_at(149, 0) in ('#eeeeee', '#e5e5e5'), 'light theme: the panes reach the window edges too'
light_status = hn('show', '-gv', 'status-style')
assert value('#{window_layout}') == layout_before_theme
snapshot('panes-light')
@@@ -452,9 -465,9 +468,9 @@@
single = hn('new-window', '-n', 'single', '-P', '-F', '#{pane_id}', '/bin/sh')
wait(lambda: value('#{pane_id}') == single and value('#{window_panes}') == '1', 'single-pane window')
- wait(lambda: not pane_outline(single) and background_at(1, 1) == '#101010'
- and background_at(0, 0) == background_at(149, 40) == '#202020',
- 'single pane keeps its focused surface inside the canvas')
+ wait(lambda: not pane_outline(single) and background_at(1, 1) == '#262626'
- and background_at(0, 0) == background_at(149, 40) == 'default',
- 'single pane sits directly on the terminal background')
++ and background_at(0, 0) == background_at(149, 40) == '#262626',
++ 'a single pane fills the window, to its edges')
snapshot('panes-single')
hn('kill-window')
wait(lambda: value('#{window_id}') == current, 'return from single-pane window')