diff --git a/codex-rs/tui/src/render/highlight.rs b/codex-rs/tui/src/render/highlight.rs index 5f504d5846..867d111f31 100644 --- a/codex-rs/tui/src/render/highlight.rs +++ b/codex-rs/tui/src/render/highlight.rs @@ -106,20 +106,31 @@ fn push_segment(lines: &mut Vec>, segment: &str, style: Option Vec> { + if script.is_empty() { + vec![Line::from("")] + } else { + script + .split('\n') + .map(|s| Line::from(s.to_string())) + .collect() + } +} + /// Convert a bash script into per-line styled content using tree-sitter's /// bash highlight query. The highlighter is streamed so multi-line content is /// split into `Line`s while preserving style boundaries. pub(crate) fn highlight_bash_to_lines(script: &str) -> Vec> { // Runtime gate: on Windows, skip bash-specific highlighting and return plain text. if cfg!(target_os = "windows") { - return vec![script.to_string().into()]; + return plain_text_lines(script); } let mut highlighter = Highlighter::new(); let iterator = match highlighter.highlight(highlight_config(), script.as_bytes(), None, |_| None) { Ok(iter) => iter, - Err(_) => return vec![script.to_string().into()], + Err(_) => return plain_text_lines(script), }; let mut lines: Vec> = vec![Line::from("")]; @@ -138,7 +149,7 @@ pub(crate) fn highlight_bash_to_lines(script: &str) -> Vec> { let style = highlight_stack.last().map(|h| highlight_for(*h).style()); push_segment(&mut lines, &script[start..end], style); } - Err(_) => return vec![script.to_string().into()], + Err(_) => return plain_text_lines(script), } }