Package org.jline.terminal.impl
Class ITerm2Graphics
java.lang.Object
org.jline.terminal.impl.ITerm2Graphics
- All Implemented Interfaces:
TerminalGraphics
Implementation of iTerm2's Inline Images Protocol.
The iTerm2 Inline Images Protocol allows displaying images directly in the terminal
using base64-encoded data embedded in escape sequences. The protocol uses OSC (Operating
System Command) escape sequences of the form: <ESC>]1337;File=<parameters>:<base64_data><BEL>
This protocol is supported by:
- iTerm2
- Some other terminals with iTerm2 compatibility
The protocol supports various parameters for controlling image display including dimensions, positioning, and preservation of aspect ratio.
- 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 TypeMethodDescriptionconvertImage(BufferedImage image, TerminalGraphics.ImageOptions options) Converts an image to the protocol-specific format.convertImageWithExtendedOptions(BufferedImage image, TerminalGraphics.ImageOptions options, String size, String position) Converts an image with additional iTerm2-specific options.voiddisplayBackgroundImage(Terminal terminal, BufferedImage image, String position) Displays an image as a background (non-inline).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.voiddisplayImageWithPercentageSize(Terminal terminal, BufferedImage image, int widthPercent, Integer heightPercent) Displays an image with percentage-based sizing.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
-
ITerm2Graphics
public ITerm2Graphics()Creates a new ITerm2Graphics 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
-
convertImageWithExtendedOptions
public String convertImageWithExtendedOptions(BufferedImage image, TerminalGraphics.ImageOptions options, String size, String position) throws IOException Converts an image with additional iTerm2-specific options.- Parameters:
image- the image to convertoptions- display optionssize- size specification (e.g., "50%", "100px")position- position specification for non-inline images- Returns:
- the complete iTerm2 graphics protocol sequence
- Throws:
IOException- if an I/O error occurs
-
displayImageWithPercentageSize
public void displayImageWithPercentageSize(Terminal terminal, BufferedImage image, int widthPercent, Integer heightPercent) throws IOException Displays an image with percentage-based sizing.- Parameters:
terminal- the terminalimage- the image to displaywidthPercent- width as percentage of terminal widthheightPercent- height as percentage of terminal height (optional)- Throws:
IOException- if an I/O error occurs
-
displayBackgroundImage
public void displayBackgroundImage(Terminal terminal, BufferedImage image, String position) throws IOException Displays an image as a background (non-inline).- Parameters:
terminal- the terminalimage- the image to displayposition- position specification (e.g., "center", "top-left")- Throws:
IOException- if an I/O error occurs
-