Class ITermImage

java.lang.Object
org.aesh.terminal.image.ITermImage
All Implemented Interfaces:
TerminalImage

public class ITermImage extends Object implements TerminalImage
iTerm2 inline images protocol implementation.

Protocol format:

 ESC ] 1337 ; File = [arguments] : base64_data BEL
 

Supported arguments:

  • name=base64_filename - base64 encoded filename
  • size=N - file size in bytes
  • width=N or width=Npx or width=N% - display width
  • height=N or height=Npx or height=N% - display height
  • preserveAspectRatio=0|1 - whether to preserve aspect ratio
  • inline=1 - display inline (required for display)

Supported by: iTerm2, WezTerm, Mintty, VSCode terminal, Tabby, Hyper

See Also:
  • Constructor Details

    • ITermImage

      public ITermImage(byte[] imageData, String filename)
      Create an iTerm2 image from raw image data.
      Parameters:
      imageData - the image data (PNG, JPEG, GIF, etc.)
      filename - optional filename for the image
  • Method Details

    • fromFile

      public static ITermImage fromFile(Path path) throws IOException
      Create an iTerm2 image from a file.
      Parameters:
      path - path to the image file
      Returns:
      the terminal image
      Throws:
      IOException - if the file cannot be read
    • fromBytes

      public static ITermImage fromBytes(byte[] data)
      Create an iTerm2 image from raw bytes.
      Parameters:
      data - the image data
      Returns:
      the terminal image
    • widthCells

      public ITermImage widthCells(int cells)
      Set the display width in terminal cells.
      Parameters:
      cells - number of cells
      Returns:
      this image for chaining
    • heightCells

      public ITermImage heightCells(int cells)
      Set the display height in terminal cells.
      Parameters:
      cells - number of cells
      Returns:
      this image for chaining
    • widthPixels

      public ITermImage widthPixels(int pixels)
      Set the display width in pixels.
      Parameters:
      pixels - width in pixels
      Returns:
      this image for chaining
    • heightPixels

      public ITermImage heightPixels(int pixels)
      Set the display height in pixels.
      Parameters:
      pixels - height in pixels
      Returns:
      this image for chaining
    • widthPercent

      public ITermImage widthPercent(int percent)
      Set the display width as a percentage of the terminal width.
      Parameters:
      percent - percentage (1-100)
      Returns:
      this image for chaining
    • heightPercent

      public ITermImage heightPercent(int percent)
      Set the display height as a percentage of the terminal height.
      Parameters:
      percent - percentage (1-100)
      Returns:
      this image for chaining
    • preserveAspectRatio

      public ITermImage preserveAspectRatio(boolean preserve)
      Set whether to preserve the aspect ratio when resizing.
      Parameters:
      preserve - true to preserve aspect ratio
      Returns:
      this image for chaining
    • useStTerminator

      public ITermImage useStTerminator(boolean useSt)
      Use ST (ESC \) terminator instead of BEL. Some terminals prefer ST over BEL.
      Parameters:
      useSt - true to use ST terminator
      Returns:
      this image for chaining
    • encode

      public String encode()
      Description copied from interface: TerminalImage
      Encode the image as an escape sequence string ready to be written to the terminal.
      Specified by:
      encode in interface TerminalImage
      Returns:
      the escape sequence that will display the image
    • getProtocol

      public ImageProtocol getProtocol()
      Description copied from interface: TerminalImage
      Get the protocol used by this image.
      Specified by:
      getProtocol in interface TerminalImage
      Returns:
      the image protocol
    • getWidthCells

      public int getWidthCells()
      Description copied from interface: TerminalImage
      Get the display width in terminal cells. Returns -1 if width is auto-detected or not specified.
      Specified by:
      getWidthCells in interface TerminalImage
      Returns:
      width in cells, or -1 for auto
    • getHeightCells

      public int getHeightCells()
      Description copied from interface: TerminalImage
      Get the display height in terminal cells. Returns -1 if height is auto-detected or not specified.
      Specified by:
      getHeightCells in interface TerminalImage
      Returns:
      height in cells, or -1 for auto