mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
## Why Pets were unavailable in tmux even when fullscreen Codex could render Kitty images through passthrough. ## What changed - Enable pet images and picker previews in fullscreen tmux panes with Kitty passthrough, and update the unavailable notice to recommend fullscreen mode with `allow-passthrough all`. - Use pane-specific image IDs and virtual placements for pets and previews, reserving separate IDs from transcript images. Repaint underlying text when pet placeholders move or disappear. - Draw pets and previews when refreshing the fullscreen transcript, and consume preview areas once per render. ## Testing Extend the owned-screen lifecycle test to verify that preparing fullscreen enables the Kitty protocol in tmux and returning to scrollback disables it. Update `/pets` notice assertions and the popup snapshot. GitOrigin-RevId: 02c838ceb06abcbb45314e1d38ff4cde77221426
168 lines
4.7 KiB
Rust
168 lines
4.7 KiB
Rust
//! Shared preview-state model for the `/pets` side pane.
|
|
//!
|
|
//! The preview pane is intentionally small and stateful: the selection popup
|
|
//! renders it synchronously, while async preview loading updates this state
|
|
//! from outside the widget tree. Keeping the state in a mutex-backed object lets
|
|
//! the picker remember the last preview area for out-of-band image rendering
|
|
//! without requiring the rest of the popup machinery to know about pet images.
|
|
|
|
use std::sync::Arc;
|
|
use std::sync::Mutex;
|
|
|
|
use ratatui::buffer::Buffer;
|
|
use ratatui::layout::HorizontalAlignment;
|
|
use ratatui::layout::Rect;
|
|
use ratatui::style::Stylize;
|
|
use ratatui::text::Line;
|
|
use ratatui::widgets::Paragraph;
|
|
use ratatui::widgets::Widget;
|
|
|
|
use crate::render::renderable::Renderable;
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub(crate) struct PetPickerPreviewState {
|
|
inner: Arc<Mutex<PetPickerPreviewInner>>,
|
|
}
|
|
|
|
impl PetPickerPreviewState {
|
|
/// Return a renderable wrapper for the picker side pane.
|
|
///
|
|
/// The wrapper is cheap to clone and intentionally shares interior state
|
|
/// with the controller so selection-change callbacks can update the visible
|
|
/// loading/error/ready state without rebuilding the popup.
|
|
pub(crate) fn renderable(&self) -> PetPickerPreviewRenderable {
|
|
PetPickerPreviewRenderable {
|
|
inner: Arc::clone(&self.inner),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn set_loading(&self) {
|
|
self.update(|inner| {
|
|
inner.status = PetPickerPreviewStatus::Loading;
|
|
});
|
|
}
|
|
|
|
pub(crate) fn set_disabled(&self) {
|
|
self.update(|inner| {
|
|
inner.status = PetPickerPreviewStatus::Disabled;
|
|
});
|
|
}
|
|
|
|
pub(crate) fn set_ready(&self) {
|
|
self.update(|inner| {
|
|
inner.status = PetPickerPreviewStatus::Ready;
|
|
});
|
|
}
|
|
|
|
pub(crate) fn set_error(&self, message: String) {
|
|
self.update(|inner| {
|
|
inner.status = PetPickerPreviewStatus::Error { message };
|
|
});
|
|
}
|
|
|
|
pub(crate) fn clear(&self) {
|
|
self.update(|inner| {
|
|
inner.status = PetPickerPreviewStatus::Hidden;
|
|
inner.last_area = None;
|
|
});
|
|
}
|
|
|
|
pub(crate) fn take_area(&self) -> Option<Rect> {
|
|
self.inner
|
|
.lock()
|
|
.ok()
|
|
.and_then(|mut inner| inner.last_area.take())
|
|
}
|
|
|
|
fn update(&self, f: impl FnOnce(&mut PetPickerPreviewInner)) {
|
|
if let Ok(mut inner) = self.inner.lock() {
|
|
f(&mut inner);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default)]
|
|
struct PetPickerPreviewInner {
|
|
status: PetPickerPreviewStatus,
|
|
last_area: Option<Rect>,
|
|
}
|
|
|
|
#[derive(Debug, Default)]
|
|
enum PetPickerPreviewStatus {
|
|
#[default]
|
|
Hidden,
|
|
Loading,
|
|
Disabled,
|
|
Ready,
|
|
Error {
|
|
message: String,
|
|
},
|
|
}
|
|
|
|
pub(crate) struct PetPickerPreviewRenderable {
|
|
inner: Arc<Mutex<PetPickerPreviewInner>>,
|
|
}
|
|
|
|
impl Renderable for PetPickerPreviewRenderable {
|
|
fn render(&self, area: Rect, buf: &mut Buffer) {
|
|
let (title, body) = {
|
|
let Ok(mut inner) = self.inner.lock() else {
|
|
return;
|
|
};
|
|
inner.last_area = Some(area);
|
|
match &inner.status {
|
|
PetPickerPreviewStatus::Hidden => return,
|
|
PetPickerPreviewStatus::Loading => ("Loading preview...", None),
|
|
PetPickerPreviewStatus::Disabled => (
|
|
"Terminal pets disabled",
|
|
Some("No pet will be shown.".to_string()),
|
|
),
|
|
PetPickerPreviewStatus::Ready => return,
|
|
PetPickerPreviewStatus::Error { message } => {
|
|
("Preview unavailable", Some(message.clone()))
|
|
}
|
|
}
|
|
};
|
|
|
|
let text_height = if body.is_some() { 2 } else { 1 };
|
|
let text_area = centered_text_area(area, text_height);
|
|
let mut lines = vec![Line::from(title.bold())];
|
|
if let Some(body) = body {
|
|
lines.push(Line::from(body.dim()));
|
|
}
|
|
Paragraph::new(lines)
|
|
.alignment(HorizontalAlignment::Center)
|
|
.render(text_area, buf);
|
|
}
|
|
|
|
fn desired_height(&self, _width: u16) -> u16 {
|
|
4
|
|
}
|
|
}
|
|
|
|
fn centered_text_area(area: Rect, height: u16) -> Rect {
|
|
let height = height.min(area.height);
|
|
let y = area.y + area.height.saturating_sub(height) / 2;
|
|
Rect::new(area.x, y, area.width, height)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn centered_text_area_centers_vertically() {
|
|
assert_eq!(
|
|
centered_text_area(
|
|
Rect::new(
|
|
/*x*/ 5, /*y*/ 10, /*width*/ 20, /*height*/ 8
|
|
),
|
|
/*height*/ 2
|
|
),
|
|
Rect::new(
|
|
/*x*/ 5, /*y*/ 13, /*width*/ 20, /*height*/ 2
|
|
)
|
|
);
|
|
}
|
|
}
|