mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Keep Sixel pets visible during composer sparkle redraws (#65040)
## Why When composer stars fade, the terminal can clear to the end of the row and erase part of the Sixel pet image. ## What changed Leave a strip of default background at the right edge of the composer where the Sixel pet is drawn, so star redraws can update the composer without clearing through the image. ## Testing Add a terminal regression test that uses text markers to stand in for Sixel pixels. It checks that the markers survive while the stars are visible and after they disappear, and that disabling the pet restores the composer background in that area. GitOrigin-RevId: 0f55d1e5594fa503edeb13d2d262e3c73bb0366b
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: active
|
||||
---
|
||||
⠈ ⢀ ⠁ ⠂ #########
|
||||
›⠁Ask Codex to do anything ⠈ ⠁ #########
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀ #########
|
||||
@@ -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::<Vec<_>>()
|
||||
.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<String> {
|
||||
(0..buffer.area.height)
|
||||
.map(|y| {
|
||||
|
||||
@@ -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<ImageProtocol> {
|
||||
self.support.protocol()
|
||||
}
|
||||
|
||||
pub(crate) fn image_columns(&self) -> u16 {
|
||||
|
||||
Reference in New Issue
Block a user