mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## What changed Render confirmation dialogs as centered overlays while preserving the composer or parent picker behind them. Share dialog sizing and cursor placement across stacked views and full transcript rendering, with input still routed exclusively to the active dialog. Use the shared confirmation preset for prompts including full access, session archive/delete, goal changes, and log upload consent. ## Testing Add coverage for backdrop retention and cursor routing at multiple terminal sizes, and for preserving the compact viewport and composer draft after dismissing a confirmation without replaying history. Update confirmation snapshots to show the retained backdrop. GitOrigin-RevId: 026af89904ec345e2b330317b8cc844512125d0e
84 lines
2.6 KiB
Rust
84 lines
2.6 KiB
Rust
//! Exercises dialog layout independently of any production confirmation caller.
|
|
|
|
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
use ratatui::Terminal;
|
|
use ratatui::backend::TestBackend;
|
|
|
|
struct TestPane {
|
|
presentation: ViewPresentation,
|
|
}
|
|
|
|
impl BottomPaneView for TestPane {
|
|
fn presentation(&self) -> ViewPresentation {
|
|
self.presentation
|
|
}
|
|
}
|
|
|
|
impl Renderable for TestPane {
|
|
fn render(&self, area: Rect, buf: &mut Buffer) {
|
|
for y in area.top()..area.bottom() {
|
|
for x in area.left()..area.right() {
|
|
if self.presentation == ViewPresentation::Inline {
|
|
buf[(x, y)].set_symbol(".");
|
|
} else if y == area.top() {
|
|
buf[(x, y)].set_symbol("D");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn desired_height(&self, _width: u16) -> u16 {
|
|
3
|
|
}
|
|
|
|
fn cursor_pos(&self, area: Rect) -> Option<(u16, u16)> {
|
|
Some((area.x, area.y))
|
|
}
|
|
|
|
fn cursor_style(&self, _area: Rect) -> SetCursorStyle {
|
|
SetCursorStyle::SteadyBar
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn centered_dialog_retains_backdrop_and_routes_cursor() {
|
|
let backdrop = TestPane {
|
|
presentation: ViewPresentation::Inline,
|
|
};
|
|
let dialog = TestPane {
|
|
presentation: super::super::SelectionViewParams::confirmation().presentation,
|
|
};
|
|
let overlay = DialogOverlay {
|
|
backdrop: RenderableItem::Borrowed(&backdrop),
|
|
dialog: CenteredView(&dialog),
|
|
};
|
|
let mut snapshots = Vec::new();
|
|
for (width, height, expected_cursor) in [(80, 9, (4, 3)), (24, 7, (2, 2)), (12, 2, (2, 0))] {
|
|
let mut terminal = Terminal::new(TestBackend::new(width, height)).unwrap();
|
|
terminal
|
|
.draw(|frame| overlay.render(frame.area(), frame.buffer_mut()))
|
|
.unwrap();
|
|
let area = Rect::new(/*x*/ 0, /*y*/ 0, width, height);
|
|
assert_eq!(
|
|
(overlay.cursor_pos(area), overlay.cursor_style(area)),
|
|
(Some(expected_cursor), SetCursorStyle::SteadyBar)
|
|
);
|
|
let views: Vec<Box<dyn BottomPaneView>> = vec![
|
|
Box::new(TestPane {
|
|
presentation: ViewPresentation::Inline,
|
|
}),
|
|
Box::new(TestPane {
|
|
presentation: ViewPresentation::Centered,
|
|
}),
|
|
];
|
|
let stack = ViewStack(&views);
|
|
let mut stacked = Buffer::empty(area);
|
|
stack.render(area, &mut stacked);
|
|
assert_eq!(&stacked, terminal.backend().buffer());
|
|
assert_eq!(stack.cursor_pos(area), overlay.cursor_pos(area));
|
|
snapshots.push(format!("{width}x{height}\n{}", terminal.backend()));
|
|
}
|
|
insta::assert_snapshot!(snapshots.join("\n"));
|
|
}
|