Class SixelGraphics

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

public class SixelGraphics extends 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 Details

    • SixelGraphics

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

    • setSixelSupportOverride

      public static void setSixelSupportOverride(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. This method uses a combination of terminal type checking and environment variables to determine if the terminal supports Sixel graphics. The detection can be overridden using setSixelSupportOverride().
      Parameters:
      terminal - the terminal to check
      Returns:
      true if the terminal supports Sixel graphics, false otherwise
    • displayImageStatic

      public static void displayImageStatic(Terminal terminal, BufferedImage image) throws 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:
      IOException - if an I/O error occurs
    • displayImageStatic

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

      public static void displayImageStatic(Terminal terminal, InputStream inputStream) throws 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:
      IOException - if an I/O error occurs
    • convertToSixel

      public static String convertToSixel(BufferedImage image) throws 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:
      NullPointerException - if image is null
      IOException
    • 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
    • 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, 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, 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, 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, BufferedImage image, int maxWidth, int maxHeight) throws 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:
      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, 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, 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
    • getName

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

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