TUItui/images

Terminal Images

Terminal image support is implemented in indusagi/src/tui/terminal-image.ts. It detects capabilities and renders images using Kitty or iTerm2 protocols.

Capability Detection

detectCapabilities() inspects:

  • TERM_PROGRAM
  • TERM
  • COLORTERM
  • Environment variables for Kitty, WezTerm, iTerm2, Ghostty

getCapabilities() caches the result until resetCapabilitiesCache() is called.

Image Rendering

Helpers include:

  • encodeKitty(base64, options) and encodeITerm2(base64, options)
  • renderImage(base64, dimensions, options)
  • deleteKittyImage(imageId) and deleteAllKittyImages()

Dimensions

  • getImageDimensions auto-detects size for PNG, JPEG, GIF, and WebP.
  • calculateImageRows converts pixel height to terminal rows.
  • getCellDimensions and setCellDimensions manage cell size.

Image Component

Image in indusagi/src/tui/components/image.ts renders a base64 image:

  • Uses Kitty or iTerm2 if available.
  • Falls back to a text placeholder from imageFallback.
  • Accepts maxWidthCells, maxHeightCells, and optional imageId.