Files
codex/codex-rs/tui/src/transcript_image_tests.rs
T
Felipe Coury c7005a3d84 Render local Markdown images inline in TUI replies (#64254)
## Why

Markdown image references in assistant replies showed only their alt text,
so users had to open the referenced file to see the image.

## What changed

- Show previews in place of alt text in rich transcript views on supported
  terminals, including in side conversations. For example,
  `![Build chart](./chart.png)` can display the chart directly in the reply.
- Confirm that the conversation uses a local workspace before loading
  visible images off the render thread. Keep alt text as the fallback
  when a preview is unavailable, and preserve it for copying and Find.

## Testing

Add a transcript snapshot covering inline placement and fallback text,
plus tests for selection across previews, text-only Find layout, and
terminal image sizing.

GitOrigin-RevId: 6a3473d340b8771066d1f249f3d3363e1ca9f3bd
2026-11-27 04:03:51 +00:00

54 lines
1.6 KiB
Rust

#![cfg(test)]
//! Pixel-level checks for fitting previews into terminal cells.
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn padding_keeps_fitted_pixels_at_their_original_scale() {
let pixel = |x, y| image::Rgba([x as u8, y as u8, 42, 255]);
let toolbar = RgbaImage::from_fn(/*width*/ 299, /*height*/ 37, pixel);
let expected = RgbaImage::from_fn(/*width*/ 300, /*height*/ 52, |x, y| {
*toolbar
.get_pixel_checked(x, y)
.unwrap_or(&image::Rgba([0; 4]))
});
assert_eq!(
pad_to_cells(toolbar, /*cell_width*/ 12, /*cell_height*/ 26),
expected
);
}
#[test]
fn sixel_output_fits_wide_images_within_the_original_encoding_budget() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("image.png");
let load = |columns| {
TranscriptImage::load_for_cells(
&path,
columns,
ImageProtocol::Sixel,
PreviewKind::Generated,
/*cell_size*/ Some((10, 20)),
)
.unwrap()
};
let source = RgbaImage::from_fn(
/*width*/ 300,
/*height*/ 37,
|x, y| image::Rgba([x as u8, y as u8, 42, 255]),
);
source.save(&path).unwrap();
let image = load(30);
assert_eq!((image.columns, image.rows), (30, 2));
assert_eq!(image.pixels, source);
assert_eq!(load(20).pixels.dimensions(), (200, 25));
for (width, height) in [(600, 74), (900, 42), (720, 320)] {
RgbaImage::new(width, height).save(&path).unwrap();
let (w, h) = load(48).pixels.dimensions();
assert!(w * h <= 160 * 80);
assert!(w * h.div_ceil(6) <= 160 * 14);
}
}