Expand description
Image diff support for displaying image files in the TUI.
This module handles:
- Detection of image files by extension (dynamic via
imagecrate) - SVG rasterization via
resvg - Image loading, downscaling, and caching
- LRU cache eviction
Structs§
- Cached
Image - A loaded and cached image ready for display
- Image
Cache - LRU cache for loaded images
- Image
Diff State - Image diff state for a single file (before and after versions)
Constants§
- FONT_
HEIGHT_ PX - Terminal font height in pixels (used for image sizing calculations). Most monospace terminal fonts are 16 pixels tall per character cell.
- FONT_
WIDTH_ PX - Terminal font width in pixels (used for image sizing calculations). Most monospace terminal fonts are 8 pixels wide per character cell.
- IMAGE_
BOTTOM_ MARGIN - Margin between image and metadata (rows)
- IMAGE_
PANEL_ OVERHEAD - Total overhead for an image panel: borders (2) + margins (2) + metadata (1) This is subtracted from the panel height to get the available image height.
- IMAGE_
TOP_ MARGIN - Margin above the image within the panel (rows)
- MAX_
CACHED_ IMAGES - Maximum number of images to keep in cache
- MAX_
CACHE_ DIMENSION - Maximum dimension for cached images (larger images are downscaled)
- MAX_
IMAGE_ HEIGHT_ ROWS - Maximum height in terminal rows for an image diff panel. Prevents very tall images from consuming excessive vertical space.
- METADATA_
HEIGHT - Height of the metadata line below each image panel (rows)
Functions§
- center_
in_ area - Center a smaller rectangle within a larger area
- fit_
dimensions - Calculate display dimensions maintaining aspect ratio. Converts image pixel dimensions to terminal cell dimensions using font metrics, then scales to fit the available space without upscaling.
- format_
file_ size - Format file size for human-readable display
- format_
name_ from_ path - Get format name from file path extension
- is_
image_ file - Check if a file is a supported image format.
Uses the
imagecrate’s format detection - no hardcoded extension list. - is_
lfs_ pointer - Check if content is a Git LFS pointer (not actual file content)
- is_svg
- Check if a file is an SVG (handled via resvg, not image crate)
- load_
and_ cache - Load image bytes and create a cached image with optional downscaling
- load_
image_ diff - Load image diff state for a file (before and after versions).
- rasterize_
svg - Rasterize SVG bytes to a DynamicImage