diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs b/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs index 4328994ce2..624858f881 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs @@ -124,7 +124,7 @@ impl ChatComposer { .as_ref() .map_or(0, |strip| strip.desired_height(area.width) + 1); let shortcuts_above = self.shortcuts_above_composer(options); - let (composer_rect, popup_rect, mut footer_rect) = if shortcuts_above { + let (mut composer_rect, popup_rect, mut footer_rect) = if shortcuts_above { let [shortcuts, composer, footer] = Layout::vertical([ Constraint::Max(above_input), Constraint::Min(3 + voice_rows), @@ -183,6 +183,11 @@ impl ChatComposer { let available = textarea_rect.height.saturating_sub(consumed); textarea_rect.y = thumbnails.bottom(); textarea_rect.height = available - thumbnails.height; + // A default-background tail keeps fading stars from triggering a clear + // to the end of the row through an out-of-band Sixel image. + if composer_rect.width > options.surface_right_reserve { + composer_rect.width -= options.surface_right_reserve; + } ComposerLayout { thumbnails, status, diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs b/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs index a117261b1c..7fe7fc2571 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs @@ -85,6 +85,8 @@ pub(crate) struct ComposerRenderOptions<'a> { pub(crate) working_tip: Option<&'a crate::turn_tip::TurnTip>, pub(crate) warning_count: usize, pub(crate) textarea_right_reserve: u16, + /// Part of the text reserve that must also stay outside the painted surface. + pub(crate) surface_right_reserve: u16, /// Fullscreen scales the footer cap with the composer budget. Inline scrollback allows two rows. pub(crate) separate_status_line: bool, /// A centered dialog owns input while the composer is painted behind it. diff --git a/codex-rs/tui/src/chatwidget/rendering.rs b/codex-rs/tui/src/chatwidget/rendering.rs index 69fc9804c1..b2fd4c2df1 100644 --- a/codex-rs/tui/src/chatwidget/rendering.rs +++ b/codex-rs/tui/src/chatwidget/rendering.rs @@ -390,6 +390,13 @@ impl ChatWidget { } options.warning_count = self.warning_display_state.count; options.textarea_right_reserve = right_reserve; + if let Some(pet) = &self.ambient_pet + && pet.image_protocol() == Some(crate::pets::ImageProtocol::Sixel) + && self.bottom_pane.no_modal_or_popup_active() + { + options.surface_right_reserve = + right_reserve.saturating_sub(AMBIENT_PET_WRAP_GAP_COLUMNS); + } options.separate_status_line = options.command_popup_placement != crate::bottom_pane::CommandPopupPlacement::AboveComposer; let bottom_pane = self.bottom_pane.backdrop_with_options(options); diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__sixel_pet_with_stars.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__sixel_pet_with_stars.snap new file mode 100644 index 0000000000..b7b713f92a --- /dev/null +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__sixel_pet_with_stars.snap @@ -0,0 +1,7 @@ +--- +source: tui/src/chatwidget/tests/status_and_layout.rs +expression: active +--- + ⠈ ⢀ ⠁ ⠂ ######### +›⠁Ask Codex to do anything ⠈ ⠁ ######### + ⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀ ######### diff --git a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs index 1ae55e1371..96579bb0a9 100644 --- a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs +++ b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs @@ -3094,6 +3094,76 @@ async fn ambient_pet_reduces_stream_width_and_composer_text_width() { assert!(!row_tail_is_blank(&disabled_row, /*start_col*/ 69)); } +#[tokio::test] +#[serial] +async fn sparkle_redraws_leave_the_sixel_pet_intact() -> std::io::Result<()> { + use crate::test_backend::VT100Backend; + use std::io::Write; + + let (mut chat, _rx, _ops) = make_chatwidget_manual(Some("gpt-6-astra")).await; + chat.set_pet_image_support_for_tests(crate::pets::PetImageSupport::Supported( + crate::pets::ImageProtocol::Sixel, + )); + chat.install_test_ambient_pet_for_tests(/*animations_enabled*/ false); + chat.local_settings.tui.animations = true; + chat.local_settings.tui.effects.starfield = true; + crate::terminal_palette::with_test_default_colors( + crate::terminal_probe::DefaultColors { + fg: (230, 216, 255), + bg: (36, 27, 53), + }, + || { + let area = ratatui::layout::Rect::new(0, 0, 80, 7); + let mut terminal = crate::custom_terminal::Terminal::with_options(VT100Backend::new( + area.width, + area.height, + ))?; + terminal.set_viewport_area(area); + terminal.draw(|frame| chat.render(area, frame.buffer_mut()))?; + let pet = chat + .ambient_pet_draw(area, area.bottom(), /*shortcut_hud_area*/ None) + .unwrap() + .area(); + // Like Sixel pixels, these cells are outside the text diff and + // disappear if a glyph or an erase-to-end command crosses them. + let marker = "#".repeat(usize::from(pet.width)); + for y in pet.y..pet.bottom() { + write!( + terminal.backend_mut(), + "\x1b[{};{}H{marker}", + y + 1, + pet.x + 1 + )?; + } + let plain = terminal.backend().to_string(); + chat.bottom_pane + .mark_fresh_task_for_sparkle("gpt-6-astra", &chat.local_settings.tui); + terminal.draw(|frame| chat.render(area, frame.buffer_mut()))?; + let active = terminal + .backend() + .vt100() + .screen() + .rows(0, area.width) + .skip(usize::from(pet.y)) + .take(3) + .collect::>() + .join("\n"); + chat.bottom_pane.dismiss_composer_sparkle(); + terminal.draw(|frame| chat.render(area, frame.buffer_mut()))?; + assert_eq!(terminal.backend().to_string(), plain); + assert_chatwidget_snapshot!("sixel_pet_with_stars", active); + chat.disable_ambient_pet_for_session(); + terminal.draw(|frame| chat.render(area, frame.buffer_mut()))?; + let screen = terminal.backend().vt100().screen(); + assert_eq!( + screen.cell(pet.y, pet.x).unwrap().bgcolor(), + screen.cell(pet.y, 0).unwrap().bgcolor() + ); + Ok(()) + }, + ) +} + fn buffer_row_containing(buffer: &ratatui::buffer::Buffer, text: &str) -> Option { (0..buffer.area.height) .map(|y| { diff --git a/codex-rs/tui/src/pets/ambient.rs b/codex-rs/tui/src/pets/ambient.rs index a900460ff6..b5af4e7bdc 100644 --- a/codex-rs/tui/src/pets/ambient.rs +++ b/codex-rs/tui/src/pets/ambient.rs @@ -198,7 +198,11 @@ impl AmbientPet { } pub(crate) fn image_enabled(&self) -> bool { - self.support.protocol().is_some() + self.image_protocol().is_some() + } + + pub(crate) fn image_protocol(&self) -> Option { + self.support.protocol() } pub(crate) fn image_columns(&self) -> u16 {