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 branch 'feat/tui-command-panel' into feat/tui-keybinds

Tim9efee620f5f8
diff --cc tui/src/modal.rs
index 6c7c2ff37,7c8313dd4..b4bf4b75f
--- a/tui/src/modal.rs
+++ b/tui/src/modal.rs
@@@ -693,10 -621,6 +693,8 @@@ pub fn theme_options(app: &App, section
let dim = Row::new(if on { "dim:off" } else { "dim:on" }, "Dim other panes").lead(lead(on))
.detail(vec![span(if on { "on" } else { "the panes you are not in, a little quieter" }, fg(theme::MUTED))]);
styles.chain(std::iter::once(dim)).collect() }
+ // ── keys ──
+ "keys" => keybind_rows(app),
- "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" => {
@@@ -802,11 -726,9 +800,11 @@@ mod theme_row_tests
let app = app();
let rows = theme_sections(&app);
let ids: Vec<&str> = rows.iter().map(|r| r.id.as_str()).collect();
- assert_eq!(ids, vec!["section:status", "section:focus", "section:split", "section:layout", "section:theme",
+ assert_eq!(ids, vec!["section:status", "section:focus", "section:layout", "section:theme",
// ── status bar ──
- "section:bar", "section:boxes"]);
+ "section:bar", "section:boxes",
+ // ── keys ──
+ "section:keys"]);
// Each section shows its current value and opens onto a non-empty option list.
assert!(rows.iter().all(|r| !r.right.is_empty()), "each section shows a value");
for r in &rows {
@@@ -847,58 -769,10 +845,57 @@@
let status_opts = theme_options(&app, "status");
let status_ids: Vec<&str> = status_opts.iter().map(|r| r.id.as_str()).collect();
assert_eq!(status_ids, vec!["border_status:off", "border_status:top", "border_status:bottom"]);
- let split_opts = theme_options(&app, "split");
- let split_ids: Vec<&str> = split_opts.iter().map(|r| r.id.as_str()).collect();
- assert_eq!(split_ids, vec!["layout_orientation:auto", "layout_orientation:vertical", "layout_orientation:horizontal"]);
+ // (No split direction section: C-b % and C-b " choose it.)
+ assert!(theme_options(&app, "split").is_empty());
}
+ // ── keys ──
+
+ /// Keybinds: the prefixes first, then the commands grouped with their keys now. A key chosen
+ /// there is the command's (its old key given up, the command in full kept); Esc changes
+ /// nothing; the prefix is the key pressed; ⌫ leaves no second prefix.
+ #[test]
+ fn keybinds_show_every_key_grouped_and_change_one() {
+ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
+ let mut app = app();
+ let rows = keybind_rows(&app);
+ assert_eq!((rows[0].id.as_str(), rows[1].id.as_str()), ("prefix:press", "prefix2:press"));
+ let mut groups: Vec<String> = Vec::new();
+ for g in rows.iter().filter_map(|r| r.group.clone()) { if groups.last() != Some(&g) { groups.push(g) } }
+ assert_eq!(groups, ["Prefix", "Navigation", "Panes", "Swarms (windows)", "Harnesses", "General"]);
+ let right = |app: &App, title: &str| keybind_rows(app).into_iter().find(|r| r.label == title).map(|r| r.right).unwrap();
+ assert_eq!(right(&app, "Split right"), "C-b %");
+ let press = |app: &mut App, code: KeyCode, mods: KeyModifiers| crate::settings::captured(app, KeyEvent::new(code, mods));
+ let chord = |code: KeyCode| crate::keys::of(&KeyEvent::new(code, KeyModifiers::NONE));
+ // Split right onto h: % is free again.
+ let i = KEYBINDS.iter().position(|k| k.0 == "Split right").unwrap().to_string();
+ assert!(crate::settings::set_key(&mut app, "key", &i).is_some_and(|s| s.contains("Press")));
+ press(&mut app, KeyCode::Char('h'), KeyModifiers::NONE);
+ assert_eq!(app.keymap.prefix_command(&chord(KeyCode::Char('h'))).map(|b| b.command.as_str()), Some("split-window -h"));
+ assert!(app.keymap.prefix_command(&chord(KeyCode::Char('%'))).is_none());
+ assert_eq!(right(&app, "Split right"), "C-b h");
+ // Rename swarm keeps its prompt on its new key.
+ let i = KEYBINDS.iter().position(|k| k.0 == "Rename swarm…").unwrap().to_string();
+ let _ = crate::settings::set_key(&mut app, "key", &i);
+ press(&mut app, KeyCode::Char('R'), KeyModifiers::SHIFT);
+ assert!(app.keymap.prefix_command(&crate::keys::of(&KeyEvent::new(KeyCode::Char('R'), KeyModifiers::SHIFT))).is_some_and(|b| b.command.contains("command-prompt")));
+ // Esc: nothing changes.
+ let _ = crate::settings::set_key(&mut app, "key", &i);
+ press(&mut app, KeyCode::Esc, KeyModifiers::NONE);
+ assert!(app.capturing.is_none());
+ assert_eq!(app.keymap.prefix_command(&chord(KeyCode::Char('h'))).map(|b| b.command.as_str()), Some("split-window -h"));
+ // The prefix, then no second prefix.
+ let _ = crate::settings::set_key(&mut app, "prefix", "press");
+ press(&mut app, KeyCode::Char('a'), KeyModifiers::CONTROL);
+ assert_eq!(crate::keys::name(&app.keymap.prefix), "C-a");
+ let _ = crate::settings::set_key(&mut app, "prefix2", "press");
+ press(&mut app, KeyCode::Char('b'), KeyModifiers::CONTROL);
+ assert_eq!(app.keymap.prefix2.map(|c| crate::keys::name(&c)).as_deref(), Some("C-b"));
+ let _ = crate::settings::set_key(&mut app, "prefix2", "press");
+ press(&mut app, KeyCode::Backspace, KeyModifiers::NONE);
+ assert_eq!(app.keymap.prefix2, None);
+ }
+
// ── status bar ──
#[test]
diff --cc tui/src/settings.rs
index a8dc37d31,aa94df2ca..084693fd9
--- a/tui/src/settings.rs
+++ b/tui/src/settings.rs
@@@ -422,11 -317,9 +422,11 @@@ fn capital(t: &str) -> String { let mu
pub fn section_title(section: &str) -> &'static str {
match section {
"status" => "Pane titles", "focus" => "Focus",
- "split" => "Split direction", "layout" => "Layout", "theme" => "Theme",
+ "layout" => "Layout", "theme" => "Theme",
// ── status bar ──
"bar" => "Status bar", "boxes" => "Borders",
+ // ── keys ──
+ "keys" => "Keybinds",
_ => "",
}
}