- java.lang.Object
-
- org.jline.terminal.impl.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jline.terminal.impl.TerminalGraphics
TerminalGraphics.ImageOptions, TerminalGraphics.Protocol
-
-
Constructor Summary
Constructors Constructor Description SixelGraphics()Creates a new SixelGraphics instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringconvertImage(java.awt.image.BufferedImage image, TerminalGraphics.ImageOptions options)Converts an image to the protocol-specific format.static java.lang.StringconvertToSixel(java.awt.image.BufferedImage image)Converts a BufferedImage to Sixel format.voiddisplayImage(Terminal terminal, java.awt.image.BufferedImage image)Displays a BufferedImage on the terminal using this graphics protocol.voiddisplayImage(Terminal terminal, java.awt.image.BufferedImage image, int maxWidth, int maxHeight)Displays an image with size constraints.voiddisplayImage(Terminal terminal, java.awt.image.BufferedImage image, TerminalGraphics.ImageOptions options)Displays a BufferedImage on the terminal with custom options.voiddisplayImage(Terminal terminal, java.io.File file)Displays an image file on the terminal.voiddisplayImage(Terminal terminal, java.io.File file, TerminalGraphics.ImageOptions options)Displays an image file on the terminal with custom options.voiddisplayImage(Terminal terminal, java.io.InputStream inputStream)Displays an image from an input stream on the terminal.voiddisplayImage(Terminal terminal, java.io.InputStream inputStream, TerminalGraphics.ImageOptions options)Displays an image from an input stream on the terminal with custom options.static voiddisplayImageStatic(Terminal terminal, java.awt.image.BufferedImage image)Displays an image in Sixel format on the terminal.static voiddisplayImageStatic(Terminal terminal, java.io.File file)Displays an image file in Sixel format on the terminal.static voiddisplayImageStatic(Terminal terminal, java.io.InputStream inputStream)Displays an image from an input stream in Sixel format on the terminal.java.lang.StringgetDescription()Gets a description of this graphics protocol.java.lang.StringgetName()Gets a human-readable name for this graphics protocol.intgetPriority()Gets the priority of this protocol for automatic selection.TerminalGraphics.ProtocolgetProtocol()Gets the graphics protocol type supported by this implementation.static booleanisSixelSupported(Terminal terminal)Checks if the terminal supports Sixel graphics.booleanisSupported(Terminal terminal)Checks if this graphics protocol is supported by the given terminal.static voidsetSixelSupportOverride(java.lang.Boolean supported)Sets an override for sixel support detection.
-
-
-
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:
- User override via
setSixelSupportOverride(Boolean) - Runtime DA1 detection via
isModeSupported(Mode.SIXEL)(part of the batch mode probe) - 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
- User override via
-
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 onimage- 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 onfile- 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 oninputStream- 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.IOExceptionConverts 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 nulljava.io.IOException
-
getProtocol
public TerminalGraphics.Protocol getProtocol()
Description copied from interface:TerminalGraphicsGets the graphics protocol type supported by this implementation.- Specified by:
getProtocolin interfaceTerminalGraphics- Returns:
- the protocol type
-
getPriority
public int getPriority()
Description copied from interface:TerminalGraphicsGets the priority of this protocol for automatic selection. Higher values indicate higher priority.- Specified by:
getPriorityin interfaceTerminalGraphics- Returns:
- the priority value (0-100)
-
isSupported
public boolean isSupported(Terminal terminal)
Description copied from interface:TerminalGraphicsChecks if this graphics protocol is supported by the given terminal.- Specified by:
isSupportedin interfaceTerminalGraphics- 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:TerminalGraphicsDisplays a BufferedImage on the terminal using this graphics protocol.- Specified by:
displayImagein interfaceTerminalGraphics- Parameters:
terminal- the terminal to display the image onimage- 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:TerminalGraphicsDisplays an image file on the terminal.- Specified by:
displayImagein interfaceTerminalGraphics- Parameters:
terminal- the terminal to display the image onfile- 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:TerminalGraphicsDisplays an image from an input stream on the terminal.- Specified by:
displayImagein interfaceTerminalGraphics- Parameters:
terminal- the terminal to display the image oninputStream- 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 onimage- the image to displaymaxWidth- maximum width for the imagemaxHeight- 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:TerminalGraphicsDisplays a BufferedImage on the terminal with custom options.- Specified by:
displayImagein interfaceTerminalGraphics- Parameters:
terminal- the terminal to display the image onimage- the image to displayoptions- 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:TerminalGraphicsDisplays an image file on the terminal with custom options.- Specified by:
displayImagein interfaceTerminalGraphics- Parameters:
terminal- the terminal to display the image onfile- the image file to displayoptions- 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:TerminalGraphicsDisplays an image from an input stream on the terminal with custom options.- Specified by:
displayImagein interfaceTerminalGraphics- Parameters:
terminal- the terminal to display the image oninputStream- the input stream containing the image dataoptions- 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.IOExceptionDescription copied from interface:TerminalGraphicsConverts an image to the protocol-specific format. This method is useful for debugging or when you need the raw protocol data.- Specified by:
convertImagein interfaceTerminalGraphics- Parameters:
image- the image to convertoptions- 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
-
-