the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: strip ansi sequences from tab bar status (#3003)
akbash4d17957c4393
diff --git a/docs/next/CHANGELOG.md b/docs/next/CHANGELOG.mdindex 05f368084..6b1556381 100644--- a/docs/next/CHANGELOG.md+++ b/docs/next/CHANGELOG.md@@ -2,6 +2,9 @@## Unreleased+### Fixed+- Tab bar status commands now remove ESC-prefixed terminal control sequences instead of displaying their sequence bodies as text. (#3001)+## [0.8.2] - 2026-08-19### Addeddiff --git a/docs/next/website/src/content/docs/configuration.mdx b/docs/next/website/src/content/docs/configuration.mdxindex 4138c9f5b..5d4a7ab10 100644--- a/docs/next/website/src/content/docs/configuration.mdx+++ b/docs/next/website/src/content/docs/configuration.mdx@@ -299,7 +299,7 @@ tab_bar_right_separator = " · "The status area is empty by default. Add `zoom` to show a fixed `ZOOM` pill while the active tab is zoomed; the existing per-tab `Z` markers remain independent. `hostname`, `datetime`, and `command` resolve on the Herdr server, so `herdr --remote` shows the remote machine's values. Datetime entries use `strftime` formatting; directives that require a UTC offset or Unix timestamp, such as `%z` and `%s`, are rejected because the value is server-local wall-clock time.-Command entries run immediately and then at `interval_seconds` without blocking rendering or overlapping a previous run. The interval can be 1–31,536,000 seconds and the timeout can be 1–3,600 seconds. Herdr uses the last line of successful output, clears it after failure, empty output, or `timeout_seconds`, and provides the same active workspace, tab, pane, socket, binary, and working-directory context as custom command keybindings. Commands are supported on Linux, macOS, and Windows, using `/bin/sh -lc` on Linux and macOS and `cmd.exe /d /c` on Windows.+Command entries run immediately and then at `interval_seconds` without blocking rendering or overlapping a previous run. The interval can be 1–31,536,000 seconds and the timeout can be 1–3,600 seconds. Herdr uses the last line of successful output, removes ESC-prefixed terminal control sequences instead of interpreting styles, clears the entry after failure, empty output, or `timeout_seconds`, and provides the same active workspace, tab, pane, socket, binary, and working-directory context as custom command keybindings. Commands are supported on Linux, macOS, and Windows, using `/bin/sh -lc` on Linux and macOS and `cmd.exe /d /c` on Windows.Separators appear only between visible entries. Set `tab_bar_right_separator = ""` for direct concatenation. On a narrow tab row, the complete status area yields to the tabs and their controls.diff --git a/src/app/tab_bar_status.rs b/src/app/tab_bar_status.rsindex 4a617c1da..eca5a314c 100644--- a/src/app/tab_bar_status.rs+++ b/src/app/tab_bar_status.rs@@ -277,9 +277,75 @@ fn is_unicode_format_control(character: char) -> bool {fn command_output_text(output: &[u8]) -> Option<String> {let output = String::from_utf8_lossy(output);+ let output = strip_terminal_control_sequences(output.as_bytes());+ let output = String::from_utf8_lossy(&output);output.lines().next_back().and_then(sanitize_status_text)}+#[derive(Clone, Copy)]+enum ControlSequenceState {+ Text,+ Escape,+ EscapeIntermediate,+ Csi,+ Osc,+ StString,+}++fn strip_terminal_control_sequences(value: &[u8]) -> Vec<u8> {+ use ControlSequenceState::*;++ let mut output = Vec::with_capacity(value.len());+ let mut state = Text;+ for &byte in value {+ state = match (state, byte) {+ (Text, b'\x1b') => Escape,+ (Text, _) => {+ output.push(byte);+ Text+ }+ (Escape, b'[') => Csi,+ (Escape, b']') => Osc,+ (Escape, b'P' | b'X' | b'^' | b'_') => StString,+ (Escape, 0x20..=0x2f) => EscapeIntermediate,+ (Escape, 0x30..=0x7e) => Text,+ (Escape, b'\x1b') => Escape,+ (Escape, b'\x18' | b'\x1a') => Text,+ (Escape, byte) if byte.is_ascii_control() => Escape,+ (Escape, _) => {+ output.push(byte);+ Text+ }+ (EscapeIntermediate, 0x20..=0x2f) => EscapeIntermediate,+ (EscapeIntermediate, 0x30..=0x7e) => Text,+ (EscapeIntermediate, b'\x1b') => Escape,+ (EscapeIntermediate, b'\x18' | b'\x1a') => Text,+ (EscapeIntermediate, byte) if byte.is_ascii_control() => EscapeIntermediate,+ (EscapeIntermediate, _) => {+ output.push(byte);+ Text+ }+ (Csi, 0x20..=0x3f) => Csi,+ (Csi, 0x40..=0x7e) => Text,+ (Csi, b'\x1b') => Escape,+ (Csi, b'\x18' | b'\x1a') => Text,+ (Csi, byte) if byte.is_ascii_control() => Csi,+ (Csi, _) => {+ output.push(byte);+ Text+ }+ (Osc, b'\x07') => Text,+ (Osc, b'\x1b') => Escape,+ (Osc, b'\x18' | b'\x1a') => Text,+ (Osc, _) => Osc,+ (StString, b'\x1b') => Escape,+ (StString, b'\x18' | b'\x1a') => Text,+ (StString, _) => StString,+ };+ }+ output+}+async fn read_last_output_line(mut stdout: tokio::process::ChildStdout,) -> std::io::Result<Vec<u8>> {@@ -699,11 +765,52 @@ mod tests {fn command_output_uses_sanitized_last_line() {assert_eq!(command_output_text(b"old\n win\x1b[31mter\r\n"),- Some("win[31mter".into())+ Some("winter".into()));assert_eq!(command_output_text(b"\r\n"), None);}+ #[test]+ fn command_output_strips_ansi_style_sequences() {+ assert_eq!(+ command_output_text(b"\x1b[32mHELLO\x1b[0m"),+ Some("HELLO".into())+ );+ }++ #[test]+ fn command_output_strips_terminal_control_sequence_families() {+ assert_eq!(+ command_output_text(b"\x1b]8;;https://example.com\x1b\\link\x1b]8;;\x1b\\"),+ Some("link".into())+ );+ assert_eq!(+ command_output_text(b"\x1bPignored\x1b\\visible\x1b7"),+ Some("visible".into())+ );+ assert_eq!(command_output_text(b"\x1b[31m\x1b[0m"), None);+ assert_eq!(+ command_output_text(b"\x1b\x07[32mHELLO\x1b[0m"),+ Some("HELLO".into())+ );+ assert_eq!(+ command_output_text(b"\x1bPignored\x18VISIBLE"),+ Some("VISIBLE".into())+ );+ assert_eq!(+ command_output_text(b"\x1bPignored\x1b7VISIBLE"),+ Some("VISIBLE".into())+ );+ assert_eq!(+ command_output_text(b"\x1b]ignored\x1aVISIBLE"),+ Some("VISIBLE".into())+ );+ assert_eq!(command_output_text(b"\xc2\x1b[31m\xa2"), Some("��".into()));++ let styled = format!("\x1b[38;2;1;2;3m{}\x1b[0m", "x".repeat(80));+ assert_eq!(command_output_text(styled.as_bytes()), Some("x".repeat(80)));+ }+#[test]fn status_text_strips_bidi_and_zero_width_format_controls() {assert_eq!(