Class ITerm2Graphics

java.lang.Object
org.jline.terminal.impl.ITerm2Graphics
All Implemented Interfaces:
TerminalGraphics

public class ITerm2Graphics extends Object implements TerminalGraphics
Implementation of iTerm2's Inline Images Protocol.

The iTerm2 Inline Images Protocol allows displaying images directly in the terminal using base64-encoded data embedded in escape sequences. The protocol uses OSC (Operating System Command) escape sequences of the form: <ESC>]1337;File=<parameters>:<base64_data><BEL>

This protocol is supported by:

  • iTerm2
  • Some other terminals with iTerm2 compatibility

The protocol supports various parameters for controlling image display including dimensions, positioning, and preservation of aspect ratio.

Since:
3.30.0
See Also:
  • Constructor Details

    • ITerm2Graphics

      public ITerm2Graphics()
      Creates a new ITerm2Graphics instance.
  • Method Details

    • getProtocol

      public TerminalGraphics.Protocol getProtocol()
      Description copied from interface: TerminalGraphics
      Gets the graphics protocol type supported by this implementation.
      Specified by:
      getProtocol in interface TerminalGraphics
      Returns:
      the protocol type
    • isSupported

      public boolean isSupported(Terminal terminal)
      Description copied from interface: TerminalGraphics
      Checks if this graphics protocol is supported by the given terminal.
      Specified by:
      isSupported in interface TerminalGraphics
      Parameters:
      terminal - the terminal to check
      Returns:
      true if the protocol is supported, false otherwise
    • getPriority

      public int getPriority()
      Description copied from interface: TerminalGraphics
      Gets the priority of this protocol for automatic selection. Higher values indicate higher priority.
      Specified by:
      getPriority in interface TerminalGraphics
      Returns:
      the priority value (0-100)
    • displayImage

      public void displayImage(Terminal terminal, BufferedImage image) throws IOException
      Description copied from interface: TerminalGraphics
      Displays a BufferedImage on the terminal using this graphics protocol.
      Specified by:
      displayImage in interface TerminalGraphics
      Parameters:
      terminal - the terminal to display the image on
      image - the image to display
      Throws:
      IOException - if an I/O error occurs
    • displayImage

      public void displayImage(Terminal terminal, BufferedImage image, TerminalGraphics.ImageOptions options) throws IOException
      Description copied from interface: TerminalGraphics
      Displays a BufferedImage on the terminal with custom options.
      Specified by:
      displayImage in interface TerminalGraphics
      Parameters:
      terminal - the terminal to display the image on
      image - the image to display
      options - display options for the image
      Throws:
      IOException - if an I/O error occurs
    • displayImage

      public void displayImage(Terminal terminal, File file) throws IOException
      Description copied from interface: TerminalGraphics
      Displays an image file on the terminal.
      Specified by:
      displayImage in interface TerminalGraphics
      Parameters:
      terminal - the terminal to display the image on
      file - the image file to display
      Throws:
      IOException - if an I/O error occurs
    • displayImage

      public void displayImage(Terminal terminal, File file, TerminalGraphics.ImageOptions options) throws IOException
      Description copied from interface: TerminalGraphics
      Displays an image file on the terminal with custom options.
      Specified by:
      displayImage in interface TerminalGraphics
      Parameters:
      terminal - the terminal to display the image on
      file - the image file to display
      options - display options for the image
      Throws:
      IOException - if an I/O error occurs
    • displayImage

      public void displayImage(Terminal terminal, InputStream inputStream) throws IOException
      Description copied from interface: TerminalGraphics
      Displays an image from an input stream on the terminal.
      Specified by:
      displayImage in interface TerminalGraphics
      Parameters:
      terminal - the terminal to display the image on
      inputStream - the input stream containing the image data
      Throws:
      IOException - if an I/O error occurs
    • displayImage

      public void displayImage(Terminal terminal, InputStream inputStream, TerminalGraphics.ImageOptions options) throws IOException
      Description copied from interface: TerminalGraphics
      Displays an image from an input stream on the terminal with custom options.
      Specified by:
      displayImage in interface TerminalGraphics
      Parameters:
      terminal - the terminal to display the image on
      inputStream - the input stream containing the image data
      options - display options for the image
      Throws:
      IOException - if an I/O error occurs
    • convertImage

      public String convertImage(BufferedImage image, TerminalGraphics.ImageOptions options) throws IOException
      Description copied from interface: TerminalGraphics
      Converts an image to the protocol-specific format. This method is useful for debugging or when you need the raw protocol data.
      Specified by:
      convertImage in interface TerminalGraphics
      Parameters:
      image - the image to convert
      options - display options for the image
      Returns:
      the protocol-specific representation of the image
      Throws:
      IOException - if an I/O error occurs
    • convertImageWithExtendedOptions

      public String convertImageWithExtendedOptions(BufferedImage image, TerminalGraphics.ImageOptions options, String size, String position) throws IOException
      Converts an image with additional iTerm2-specific options.
      Parameters:
      image - the image to convert
      options - display options
      size - size specification (e.g., "50%", "100px")
      position - position specification for non-inline images
      Returns:
      the complete iTerm2 graphics protocol sequence
      Throws:
      IOException - if an I/O error occurs
    • displayImageWithPercentageSize

      public void displayImageWithPercentageSize(Terminal terminal, BufferedImage image, int widthPercent, Integer heightPercent) throws IOException
      Displays an image with percentage-based sizing.
      Parameters:
      terminal - the terminal
      image - the image to display
      widthPercent - width as percentage of terminal width
      heightPercent - height as percentage of terminal height (optional)
      Throws:
      IOException - if an I/O error occurs
    • displayBackgroundImage

      public void displayBackgroundImage(Terminal terminal, BufferedImage image, String position) throws IOException
      Displays an image as a background (non-inline).
      Parameters:
      terminal - the terminal
      image - the image to display
      position - position specification (e.g., "center", "top-left")
      Throws:
      IOException - if an I/O error occurs