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 Detail

      • getProtocol

        TerminalGraphics.Protocol 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,
                          java.awt.image.BufferedImage image)
                   throws java.io.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:
        java.io.IOException - if an I/O error occurs
        java.lang.UnsupportedOperationException - if the protocol is not supported
      • displayImage

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

        void displayImage​(Terminal terminal,
                          java.io.File file)
                   throws java.io.IOException
        Displays an image file on the terminal.
        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
        java.lang.UnsupportedOperationException - if the protocol is not supported
      • displayImage

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

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

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

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