Interface TerminalGraphics

All Known Implementing Classes:
ITerm2Graphics, KittyGraphics, SixelGraphics

public interface TerminalGraphics
Common interface for terminal graphics protocols.

This interface provides a unified API for displaying images in terminals using various graphics protocols such as Sixel, Kitty Graphics Protocol, and iTerm2 Inline Images Protocol.

Different terminals support different graphics protocols:

  • Sixel - Supported by xterm, iTerm2, foot, WezTerm, etc.
  • Kitty Graphics Protocol - Supported by Kitty, Ghostty, WezTerm
  • iTerm2 Inline Images - Supported by iTerm2

The implementation automatically detects which protocols are supported and uses the best available option.

Since:
3.30.0
  • Method Details

    • getProtocol

      Gets the graphics protocol type supported by this implementation.
      Returns:
      the protocol type
    • isSupported

      boolean isSupported(Terminal terminal)
      Checks if this graphics protocol is supported by the given terminal.
      Parameters:
      terminal - the terminal to check
      Returns:
      true if the protocol is supported, false otherwise
    • getPriority

      int getPriority()
      Gets the priority of this protocol for automatic selection. Higher values indicate higher priority.
      Returns:
      the priority value (0-100)
    • displayImage

      void displayImage(Terminal terminal, BufferedImage image) throws IOException
      Displays a BufferedImage on the terminal using this graphics protocol.
      Parameters:
      terminal - the terminal to display the image on
      image - the image to display
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the protocol is not supported
    • displayImage

      void displayImage(Terminal terminal, BufferedImage image, TerminalGraphics.ImageOptions options) throws IOException
      Displays a BufferedImage on the terminal with custom options.
      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
      UnsupportedOperationException - if the protocol is not supported
    • displayImage

      void displayImage(Terminal terminal, File file) throws IOException
      Displays an image file on the terminal.
      Parameters:
      terminal - the terminal to display the image on
      file - the image file to display
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the protocol is not supported
    • displayImage

      void displayImage(Terminal terminal, File file, TerminalGraphics.ImageOptions options) throws IOException
      Displays an image file on the terminal with custom options.
      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
      UnsupportedOperationException - if the protocol is not supported
    • displayImage

      void displayImage(Terminal terminal, InputStream inputStream) throws IOException
      Displays an image from an input stream on the terminal.
      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
      UnsupportedOperationException - if the protocol is not supported
    • displayImage

      void displayImage(Terminal terminal, InputStream inputStream, TerminalGraphics.ImageOptions options) throws IOException
      Displays an image from an input stream on the terminal with custom options.
      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
      UnsupportedOperationException - if the protocol is not supported
    • convertImage

      String convertImage(BufferedImage image, TerminalGraphics.ImageOptions options) throws IOException
      Converts an image to the protocol-specific format. This method is useful for debugging or when you need the raw protocol data.
      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