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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
tui: honour the terminal's own foreground and invert the status bar
Tim157c9b0682d1
diff --git a/tui/src/app.rs b/tui/src/app.rsindex 88797c616..f1603ac65 100644--- a/tui/src/app.rs+++ b/tui/src/app.rs@@ -3647,12 +3647,13 @@ impl App {if let Some(c) = c { own = true; s = if fg { s.fg(c) } else { s.bg(c) } }}// No status colours of its own and the terminal has told us what it looks like: the bar- // takes the theme's own colours — its background the terminal's background, its text the- // readable opposite — so it is a visible bar in the theme (a dark bar, light text on a- // dark terminal), not a transparent one, and not tmux's stock green.+ // swaps the theme's own colours — its background the terminal's foreground, its text the+ // terminal's background — so the bar is the theme's text colour with the theme's+ // background as its lettering (an ivory bar with dark text on a dark terminal), not a+ // transparent one, and not tmux's stock green.if !own && !self.options.pane_look() && !self.options.tmux_look() {let (bg, fg, _) = crate::theme::palette();- s = s.bg(bg).fg(fg);+ s = s.bg(fg).fg(bg);}s}diff --git a/tui/src/term_input.rs b/tui/src/term_input.rsindex d426cde85..63157d9ad 100644--- a/tui/src/term_input.rs+++ b/tui/src/term_input.rs@@ -11,7 +11,7 @@ mod parse;enum InternalEvent { Event(Event), CursorPosition(u16, u16), KeyboardEnhancementFlags(KeyboardEnhancementFlags), PrimaryDeviceAttributes }#[derive(Debug, PartialEq)]-enum Item { Input(Event), Terminal(Option<String>), Background(Option<String>) }+enum Item { Input(Event), Terminal(Option<String>), Foreground(Option<String>), Background(Option<String>) }#[derive(Default)]struct Decoder { pending: Vec<u8> }@@ -28,6 +28,15 @@ impl Decoder {if let Some(end) = end { out.push(Item::Terminal(Some(String::from_utf8_lossy(&p[4..end]).into_owned()))); self.pending.clear(); }continue;}+ // OSC 10 default-foreground answer from `ask_terminal`, `\x1b]10;rgb:…\x07` (or+ // `#rrggbb`). Same hold-till-terminator rule, so a colour reply is never a key and+ // interleaved typeahead stays typeahead. The colour body is the one OSC 11 uses.+ if b"\x1b]10;".starts_with(p) { continue }+ if p.starts_with(b"\x1b]10;") && p.len() < 4096 {+ let end = if p.ends_with(b"\x1b\\") { Some(p.len() - 2) } else if p.ends_with(b"\x07") { Some(p.len() - 1) } else { None };+ if let Some(end) = end { out.push(Item::Foreground(parse_osc11(&String::from_utf8_lossy(&p[5..end])))); self.pending.clear(); }+ continue;+ }// OSC 11 default-background answer from `ask_terminal`, `\x1b]11;rgb:…\x07`// (or `#rrggbb`). Same hold-till-terminator rule as XDA, so a query reply never// becomes a key, and interleaved typeahead stays typeahead.@@ -131,6 +140,10 @@ pub fn read(keys: tokio::sync::mpsc::UnboundedSender<crate::event::Event>) {if !crate::term_out::terminal_answer(name) { continue }crate::event::Event::Apply(Box::new(|app| app.redraw_all = true))}+ Item::Foreground(fg) => {+ crate::term_out::set_terminal_colours(None, fg);+ crate::event::Event::Apply(Box::new(|app| { app.push_theme(); app.redraw_all = true; }))+ }Item::Background(bg) => {crate::term_out::set_terminal_colours(bg, None);crate::event::Event::Apply(Box::new(|app| { app.push_theme(); app.redraw_all = true; }))@@ -181,6 +194,16 @@ mod tests {assert_eq!(decoder.escape(), vec![Item::Input(Event::Key(KeyEvent::new(KeyCode::Char('P'), KeyModifiers::SHIFT | KeyModifiers::ALT)))]);}#[test]+ fn osc10_foreground_answer_becomes_theme_and_spares_typeahead() {+ let mut decoder = Decoder::default();+ let mut items = Vec::new();+ for b in b"ls\r\x1b]10;rgb:ffff/0000/0000\x07echo done" { items.extend(decoder.push(&[*b], true)); }+ let fgs: Vec<_> = items.iter().filter_map(|i| if let Item::Foreground(n) = i { Some(n.clone()) } else { None }).collect();+ assert_eq!(fgs, vec![Some("#ff0000".into())]);+ let text: String = items.iter().filter_map(|i| match i { Item::Input(Event::Key(k)) => match k.code { KeyCode::Char(c) => Some(c), KeyCode::Enter => Some('\r'), _ => None }, _ => None }).collect();+ assert_eq!(text, "ls\recho done");+ }+ #[test]fn osc11_background_answers_become_theme_and_spare_typeahead() {let mut decoder = Decoder::default();let mut items = Vec::new();diff --git a/tui/src/term_out.rs b/tui/src/term_out.rsindex 40b52dbab..78a47cf01 100644--- a/tui/src/term_out.rs+++ b/tui/src/term_out.rs@@ -195,11 +195,13 @@ static TERMINAL: std::sync::OnceLock<String> = std::sync::OnceLock::new();static TERMINAL_ANSWERED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);/// Query without waiting: the normal input reader separates replies from typeahead.-/// OSC 11 (default background) is asked too: hn reports it to each machine's daemon-/// (`theme_set`) so agent panes are painted to match, exactly as the desktop app does.+/// OSC 11 (default background) is asked, and now OSC 10 (default foreground) too: hn reports+/// them to each machine's daemon (`theme_set`) so agent panes are painted to match, exactly as+/// the desktop app does. Asking OSC 10 is what keeps hn's chrome on the terminal's own+/// foreground (an ivory/cream), not a white computed from the background.pub fn ask_terminal() {let mut out = io::stdout();- let _ = out.write_all(b"\x1b[>q\x1b[c\x1b]11;?\x07");+ let _ = out.write_all(b"\x1b[>q\x1b[c\x1b]11;?\x07\x1b]10;?\x07");let _ = out.flush();}