Class SixelGraphics

  • All Implemented Interfaces:
    TerminalGraphics

    public class SixelGraphics
    extends java.lang.Object
    implements TerminalGraphics
    Implementation of the Sixel Graphics Protocol.

    Sixel is a bitmap graphics format supported by some terminals that allows displaying raster graphics directly in the terminal. This class provides methods for converting images to Sixel format and displaying them on terminals that support Sixel graphics.

    The name "Sixel" comes from "six pixels" because each character cell represents 6 pixels arranged vertically.

    Sixel graphics are supported by many terminals including:

    • xterm
    • iTerm2
    • foot
    • WezTerm
    • Konsole
    • VS Code (with enableImages setting)
    Since:
    3.30.0
    • Constructor Detail

      • SixelGraphics

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

      • setSixelSupportOverride

        public static void setSixelSupportOverride​(java.lang.Boolean supported)
        Sets an override for sixel support detection. This can be used to explicitly enable or disable sixel support, regardless of terminal detection.
        Parameters:
        supported - true to force enable sixel support, false to force disable, null to use automatic detection
      • isSixelSupported

        public static boolean isSixelSupported​(Terminal terminal)
        Checks if the terminal supports Sixel graphics.

        Detection priority:

        1. User override via setSixelSupportOverride(Boolean)
        2. Runtime DA1 detection via isModeSupported(Mode.SIXEL) (part of the batch mode probe)
        3. Static detection based on terminal type and environment variables
        Parameters:
        terminal - the terminal to check
        Returns:
        true if the terminal supports Sixel graphics, false otherwise
      • displayImageStatic

        public static void displayImageStatic​(Terminal terminal,
                                              java.awt.image.BufferedImage image)
                                       throws java.io.IOException
        Displays an image in Sixel format on the terminal.
        Parameters:
        terminal - the terminal to display the image on
        image - the image to display
        Throws:
        java.io.IOException - if an I/O error occurs
      • displayImageStatic

        public static void displayImageStatic​(Terminal terminal,
                                              java.io.File file)
                                       throws java.io.IOException
        Displays an image file in Sixel format 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
      • displayImageStatic

        public static void displayImageStatic​(Terminal terminal,
                                              java.io.InputStream inputStream)
                                       throws java.io.IOException
        Displays an image from an input stream in Sixel format 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
      • convertToSixel

        public static java.lang.String convertToSixel​(java.awt.image.BufferedImage image)
                                               throws java.io.IOException
        Converts a BufferedImage to Sixel format.
        Parameters:
        image - the image to convert (must not be null)
        Returns:
        a string containing the Sixel data
        Throws:
        java.lang.NullPointerException - if image is null
        java.io.IOException
      • 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)
      • 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
      • 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.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.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.awt.image.BufferedImage image,
                                 int maxWidth,
                                 int maxHeight)
                          throws java.io.IOException
        Displays an image with size constraints. This is a convenience method not part of the TerminalGraphics interface.
        Parameters:
        terminal - the terminal to display the image on
        image - the image to display
        maxWidth - maximum width for the image
        maxHeight - maximum height for the image
        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,
                                 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,
                                 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
      • getName

        public java.lang.String getName()
        Gets a human-readable name for this graphics protocol.
        Returns:
        the protocol name
      • getDescription

        public java.lang.String getDescription()
        Gets a description of this graphics protocol.
        Returns:
        a description of the protocol