Package org.jline.terminal.impl
Class KittyGraphics
java.lang.Object
org.jline.terminal.impl.KittyGraphics
- All Implemented Interfaces:
TerminalGraphics
Implementation of Kitty's Graphics Protocol.
The Kitty Graphics Protocol is a modern terminal graphics protocol that supports
advanced features like animations, transparency, and efficient image transmission.
It uses escape sequences of the form: <ESC>_G<control data>;<payload><ESC>\
This protocol is supported by:
- Kitty terminal
- WezTerm
- Ghostty (planned)
The protocol supports various transmission formats including base64 encoding, direct file paths, and chunked transmission for large images.
- Since:
- 3.30.0
- See Also:
-
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 TypeMethodDescriptionvoidclearAllImages(Terminal terminal) Clears all images from the terminal.convertImage(BufferedImage image, TerminalGraphics.ImageOptions options) Converts an image to the protocol-specific format.convertImageChunked(BufferedImage image, TerminalGraphics.ImageOptions options, int chunkSize) Converts an image with chunked transmission for large images.voiddeleteImage(Terminal terminal, int imageId) Deletes an image from the terminal's memory.voiddisplayImage(Terminal terminal, BufferedImage image) Displays a BufferedImage on the terminal using this graphics protocol.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.intGets the priority of this protocol for automatic selection.Gets the graphics protocol type supported by this implementation.booleanisSupported(Terminal terminal) Checks if this graphics protocol is supported by the given terminal.
-
Constructor Details
-
KittyGraphics
public KittyGraphics()Creates a new KittyGraphics instance.
-
-
Method Details
-
getProtocol
Description copied from interface:TerminalGraphicsGets the graphics protocol type supported by this implementation.- Specified by:
getProtocolin interfaceTerminalGraphics- Returns:
- the protocol type
-
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
-
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)
-
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
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
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
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
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, 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
-
convertImageChunked
public String convertImageChunked(BufferedImage image, TerminalGraphics.ImageOptions options, int chunkSize) throws IOException Converts an image with chunked transmission for large images. This method splits large base64 data into chunks to avoid terminal buffer limits.- Parameters:
image- the image to convertoptions- display optionschunkSize- maximum size of each chunk (default: 4096)- Returns:
- the complete Kitty graphics protocol sequence
- Throws:
IOException- if an I/O error occurs
-
deleteImage
Deletes an image from the terminal's memory.- Parameters:
terminal- the terminalimageId- the ID of the image to delete- Throws:
IOException- if an I/O error occurs
-
clearAllImages
Clears all images from the terminal.- Parameters:
terminal- the terminal- Throws:
IOException- if an I/O error occurs
-