From c6b00eacb985a0da05093044e8f6c04599943808 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 24 Nov 2026 20:10:22 +0000 Subject: [PATCH] Add composer borders when the terminal background is unknown (#63741) ## Why When Codex cannot detect the terminal background, the composer loses the fill that sets it apart from the surrounding UI. Guessing a fill color could hide the terminal cursor. ## What changed Use gray top and bottom borders to mark the composer when it has no background fill, leaving the terminal background visible. Draw the borders only when there is room for the text area and the terminal can render a color. ## Testing Add a snapshot for a missing terminal palette that shows the borders around a draft with a file mention and an image attachment. GitOrigin-RevId: da74996fcde8f669c7b1577fa93a7744ad65e4f6 --- codex-rs/tui/src/bottom_pane/chat_composer.rs | 31 +++++++++++++++---- ...ts__missing_terminal_palette_composer.snap | 27 ++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__missing_terminal_palette_composer.snap diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index fb524fb27b..4ca11b7723 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -350,6 +350,7 @@ use ratatui::style::Stylize; use ratatui::text::Line; use ratatui::text::Span; use ratatui::widgets::Block; +use ratatui::widgets::Borders; use ratatui::widgets::Paragraph; use ratatui::widgets::StatefulWidgetRef; use ratatui::widgets::Widget; @@ -4911,7 +4912,17 @@ impl ChatComposer { selection.register(footer_rect.intersection(buf.area), changed); } let style = user_message_style(); - Block::default().style(style).render(composer_rect, buf); + let mut block = Block::default().style(style); + // Mark the padding without guessing a fill that could hide the terminal's cursor. + if style.bg.is_none() && !textarea_rect.is_empty() { + let gray = crate::terminal_palette::best_color((128, 128, 128)); + if gray != Color::Reset { + block = block + .borders(Borders::TOP | Borders::BOTTOM) + .border_style(gray); + } + } + block.render(composer_rect, buf); if let Some(previews) = options.image_previews { previews.render( thumbnails, @@ -5155,17 +5166,17 @@ mod tests { } #[test] - fn light_terminal_palette_renders_light_composer_snapshot() { + fn composer_with_light_or_missing_palette() { let colors = crate::terminal_probe::DefaultColors { fg: (0x55, 0x57, 0x53), bg: (0xff, 0xff, 0xff), }; + let (mut composer, _rx) = new_test_composer(); + let area = Rect::new( + /*x*/ 0, /*y*/ 0, /*width*/ 48, /*height*/ 6, + ); crate::terminal_palette::with_test_default_colors(colors, || { - let (composer, _rx) = new_test_composer(); - let area = Rect::new( - /*x*/ 0, /*y*/ 0, /*width*/ 48, /*height*/ 6, - ); let mut buffer = Buffer::empty(area); composer.render(area, &mut buffer); @@ -5175,6 +5186,14 @@ mod tests { ); insta::assert_snapshot!("light_terminal_palette_composer", format!("{buffer:?}")); }); + crate::terminal_palette::with_test_default_colors(/*colors*/ None, || { + composer.draft.textarea.insert_str("Explain "); + composer.draft.textarea.insert_element("@file.rs"); + composer.set_remote_image_urls(vec!["https://example.com/image.png".to_string()]); + let mut buffer = Buffer::empty(area); + composer.render(area, &mut buffer); + insta::assert_snapshot!("missing_terminal_palette_composer", format!("{buffer:?}")); + }); } #[test] diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__missing_terminal_palette_composer.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__missing_terminal_palette_composer.snap new file mode 100644 index 0000000000..c99a96940e --- /dev/null +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__missing_terminal_palette_composer.snap @@ -0,0 +1,27 @@ +--- +source: tui/src/bottom_pane/chat_composer.rs +expression: "format!(\"{buffer:?}\")" +--- +Buffer { + area: Rect { x: 0, y: 0, width: 48, height: 6 }, + content: [ + "────────────────────────────────────────────────", + " [Image #1] ", + " ", + "› Explain @file.rs ", + "────────────────────────────────────────────────", + " 100% context left ", + ], + styles: [ + x: 0, y: 0, fg: Rgb(128, 128, 128), bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 2, y: 1, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE, + x: 12, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 10, y: 3, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE, + x: 18, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 4, fg: Rgb(128, 128, 128), bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + ] +}