Package org.jline.terminal.impl
Class TerminalGraphicsManager
java.lang.Object
org.jline.terminal.impl.TerminalGraphicsManager
Manager for terminal graphics protocols.
This class provides a unified interface for displaying images in terminals using the best available graphics protocol. It automatically detects which protocols are supported by the terminal and selects the most appropriate one.
The manager supports multiple graphics protocols:
- Kitty Graphics Protocol - Modern, feature-rich protocol
- iTerm2 Inline Images - iTerm2's proprietary protocol
- Sixel - Widely supported legacy protocol
Protocols are selected based on priority and terminal support. Higher priority protocols are preferred when multiple protocols are available.
- Since:
- 3.30.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddisplayImage(Terminal terminal, BufferedImage image) Displays a BufferedImage on the terminal using the best available protocol.static voiddisplayImage(Terminal terminal, BufferedImage image, TerminalGraphics.ImageOptions options) Displays a BufferedImage on the terminal with custom options.static voiddisplayImage(Terminal terminal, File file) Displays an image file on the terminal using the best available protocol.static voiddisplayImage(Terminal terminal, File file, TerminalGraphics.ImageOptions options) Displays an image file on the terminal with custom options.static voiddisplayImage(Terminal terminal, InputStream inputStream) Displays an image from an input stream on the terminal using the best available protocol.static voiddisplayImage(Terminal terminal, InputStream inputStream, TerminalGraphics.ImageOptions options) Displays an image from an input stream on the terminal with custom options.static voidforceProtocol(TerminalGraphics.Protocol protocol) Forces the use of a specific graphics protocol, overriding automatic detection.static List<TerminalGraphics> Gets all available graphics protocols.static Optional<TerminalGraphics> getBestProtocol(Terminal terminal) Finds the best graphics protocol for the given terminal.static TerminalGraphics.ProtocolGets the forced protocol, if any.static List<TerminalGraphics> getSupportedProtocols(Terminal terminal) Gets all graphics protocols supported by the given terminal.static booleanisGraphicsSupported(Terminal terminal) Checks if any graphics protocol is supported by the given terminal.static booleanChecks if the java.desktop module is available.static voidregisterProtocol(TerminalGraphics protocol) Registers a graphics protocol implementation.
-
Constructor Details
-
TerminalGraphicsManager
public TerminalGraphicsManager()Creates a new TerminalGraphicsManager instance.
-
-
Method Details
-
registerProtocol
Registers a graphics protocol implementation. The protocol list is automatically re-sorted by priority after registration. If a protocol of the same type is already registered, it will not be added again.- Parameters:
protocol- the protocol implementation to register
-
forceProtocol
Forces the use of a specific graphics protocol, overriding automatic detection. This is useful for testing or when automatic detection fails.- Parameters:
protocol- the protocol to force, or null to enable automatic detection
-
getForcedProtocol
Gets the forced protocol, if any.- Returns:
- the forced protocol, or null if automatic detection is enabled
-
isJavaDesktopAvailable
public static boolean isJavaDesktopAvailable()Checks if the java.desktop module is available. Graphics features require java.desktop for AWT imaging types.- Returns:
- true if java.desktop is available, false otherwise
-
getBestProtocol
Finds the best graphics protocol for the given terminal.- Parameters:
terminal- the terminal to check- Returns:
- the best available graphics protocol, or empty if none are supported
-
getAvailableProtocols
Gets all available graphics protocols.- Returns:
- a list of all registered graphics protocols
-
getSupportedProtocols
Gets all graphics protocols supported by the given terminal.- Parameters:
terminal- the terminal to check- Returns:
- a list of supported graphics protocols, sorted by priority
-
isGraphicsSupported
Checks if any graphics protocol is supported by the given terminal.- Parameters:
terminal- the terminal to check- Returns:
- true if at least one graphics protocol is supported
-
displayImage
Displays a BufferedImage on the terminal using the best available protocol.- Parameters:
terminal- the terminal to display the image onimage- the image to display- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if no graphics protocol is supported or java.desktop is not available
-
displayImage
public static void displayImage(Terminal terminal, BufferedImage image, TerminalGraphics.ImageOptions options) throws IOException Displays a BufferedImage on the terminal with custom options.- 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 occursUnsupportedOperationException- if no graphics protocol is supported or java.desktop is not available
-
displayImage
Displays an image file on the terminal using the best available protocol.- Parameters:
terminal- the terminal to display the image onfile- the image file to display- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if no graphics protocol is supported or java.desktop is not available
-
displayImage
public static void displayImage(Terminal terminal, File file, TerminalGraphics.ImageOptions options) throws IOException Displays an image file on the terminal with custom options.- 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 occursUnsupportedOperationException- if no graphics protocol is supported or java.desktop is not available
-
displayImage
Displays an image from an input stream on the terminal using the best available protocol.- Parameters:
terminal- the terminal to display the image oninputStream- the input stream containing the image data- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if no graphics protocol is supported or java.desktop is not available
-
displayImage
public static void displayImage(Terminal terminal, InputStream inputStream, TerminalGraphics.ImageOptions options) throws IOException Displays an image from an input stream on the terminal with custom options.- 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 occursUnsupportedOperationException- if no graphics protocol is supported or java.desktop is not available
-