Package org.jline.terminal.impl
Class SixelGraphics
java.lang.Object
org.jline.terminal.impl.SixelGraphics
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionconvertImage(BufferedImage image, TerminalGraphics.ImageOptions options) Converts an image to the protocol-specific format.static StringconvertToSixel(BufferedImage image) Converts a BufferedImage to Sixel format.voiddisplayImage(Terminal terminal, BufferedImage image) Displays a BufferedImage on the terminal using this graphics protocol.voiddisplayImage(Terminal terminal, BufferedImage image, int maxWidth, int maxHeight) Displays an image with size constraints.voiddisplayImage(Terminal terminal, BufferedImage image, TerminalGraphics.ImageOptions options) Displays a BufferedImage on the terminal with custom options.voiddisplayImage(Terminal terminal, File file) Displays an image file on the terminal.voiddisplayImage(Terminal terminal, File file, TerminalGraphics.ImageOptions options) Displays an image file on the terminal with custom options.voiddisplayImage(Terminal terminal, InputStream inputStream) Displays an image from an input stream on the terminal.voiddisplayImage(Terminal terminal, InputStream inputStream, TerminalGraphics.ImageOptions options) Displays an image from an input stream on the terminal with custom options.static voiddisplayImageStatic(Terminal terminal, BufferedImage image) Displays an image in Sixel format on the terminal.static voiddisplayImageStatic(Terminal terminal, File file) Displays an image file in Sixel format on the terminal.static voiddisplayImageStatic(Terminal terminal, InputStream inputStream) Displays an image from an input stream in Sixel format on the terminal.Gets a description of this graphics protocol.getName()Gets a human-readable name for this graphics protocol.intGets the priority of this protocol for automatic selection.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(Boolean supported) Sets an override for sixel support detection.
-
Constructor Details
-
SixelGraphics
public SixelGraphics()Creates a new SixelGraphics instance.
-
-
Method Details
-
setSixelSupportOverride
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
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
Displays an image in Sixel format on the terminal.- Parameters:
terminal- the terminal to display the image onimage- the image to display- Throws:
IOException- if an I/O error occurs
-
displayImageStatic
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:
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 oninputStream- the input stream containing the image data- Throws:
IOException- if an I/O error occurs
-
convertToSixel
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 nullIOException
-
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
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
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:
IOException- if an I/O error occurs
-
displayImage
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:
IOException- if an I/O error occurs
-
displayImage
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:
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 onimage- the image to displaymaxWidth- maximum width for the imagemaxHeight- 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: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:
IOException- if an I/O error occurs
-
displayImage
public void displayImage(Terminal terminal, File file, TerminalGraphics.ImageOptions options) throws 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:
IOException- if an I/O error occurs
-
displayImage
public void displayImage(Terminal terminal, InputStream inputStream, TerminalGraphics.ImageOptions options) throws 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:
IOException- if an I/O error occurs
-
convertImage
public String convertImage(BufferedImage image, TerminalGraphics.ImageOptions options) throws IOException Description 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:
IOException- if an I/O error occurs
-
getName
Gets a human-readable name for this graphics protocol.- Returns:
- the protocol name
-
getDescription
Gets a description of this graphics protocol.- Returns:
- a description of the protocol
-