Class KittyGraphics

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

public class KittyGraphics extends Object implements TerminalGraphics
Implementation of Kitty's Graphics Protocol.

The Kitty Graphics Protocol is a modern terminal graphics protocol that supports advanced features like animations, transparency, and efficient image transmission. It uses escape sequences of the form: <ESC>_G<control data>;<payload><ESC>\

This protocol is supported by:

  • Kitty terminal
  • WezTerm
  • Ghostty (planned)

The protocol supports various transmission formats including base64 encoding, direct file paths, and chunked transmission for large images.

Since:
3.30.0
See Also:
  • Constructor Details

    • KittyGraphics

      public KittyGraphics()
      Creates a new KittyGraphics 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
    • convertImageChunked

      public String convertImageChunked(BufferedImage image, TerminalGraphics.ImageOptions options, int chunkSize) throws IOException
      Converts an image with chunked transmission for large images. This method splits large base64 data into chunks to avoid terminal buffer limits.
      Parameters:
      image - the image to convert
      options - display options
      chunkSize - maximum size of each chunk (default: 4096)
      Returns:
      the complete Kitty graphics protocol sequence
      Throws:
      IOException - if an I/O error occurs
    • deleteImage

      public void deleteImage(Terminal terminal, int imageId) throws IOException
      Deletes an image from the terminal's memory.
      Parameters:
      terminal - the terminal
      imageId - the ID of the image to delete
      Throws:
      IOException - if an I/O error occurs
    • clearAllImages

      public void clearAllImages(Terminal terminal) throws IOException
      Clears all images from the terminal.
      Parameters:
      terminal - the terminal
      Throws:
      IOException - if an I/O error occurs