Class KittyGraphics

  • All Implemented Interfaces:
    TerminalGraphics

    public class KittyGraphics
    extends java.lang.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:
    Kitty Graphics Protocol
    • Constructor Detail

      • KittyGraphics

        public KittyGraphics()
        Creates a new KittyGraphics instance.
    • Method Detail

      • 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,
                                 java.awt.image.BufferedImage image)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • displayImage

        public void displayImage​(Terminal terminal,
                                 java.awt.image.BufferedImage image,
                                 TerminalGraphics.ImageOptions options)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • displayImage

        public void displayImage​(Terminal terminal,
                                 java.io.File file)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • displayImage

        public void displayImage​(Terminal terminal,
                                 java.io.File file,
                                 TerminalGraphics.ImageOptions options)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • displayImage

        public void displayImage​(Terminal terminal,
                                 java.io.InputStream inputStream)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • displayImage

        public void displayImage​(Terminal terminal,
                                 java.io.InputStream inputStream,
                                 TerminalGraphics.ImageOptions options)
                          throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • convertImage

        public java.lang.String convertImage​(java.awt.image.BufferedImage image,
                                             TerminalGraphics.ImageOptions options)
                                      throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • convertImageChunked

        public java.lang.String convertImageChunked​(java.awt.image.BufferedImage image,
                                                    TerminalGraphics.ImageOptions options,
                                                    int chunkSize)
                                             throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • deleteImage

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

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