Package org.aesh.terminal.image
Class TerminalImageBuilder
java.lang.Object
org.aesh.terminal.image.TerminalImageBuilder
Builder for creating terminal images with automatic protocol detection.
Example usage:
TerminalImage image = TerminalImageBuilder.builder(connection.device())
.file(Paths.get("image.png"))
.widthCells(40)
.build();
connection.write(image.encode());
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the terminal image.static TerminalImageBuilderCreate a builder that auto-detects the best image protocol for the device.static TerminalImageBuilderbuilder(ImageProtocol protocol) Create a builder using a specific image protocol.data(byte[] data) Set the image data from raw bytes.static ImageProtocoldetectProtocol(Device device) Detect the best image protocol for the given device.Set the image data from a file.Set the filename (used by iTerm2 protocol).Get the protocol that will be used.heightCells(int cells) Set the display height in terminal cells.heightPixels(int pixels) Set the display height in pixels (iTerm2 and Sixel).booleanCheck if image display is supported.preserveAspectRatio(boolean preserve) Set whether to preserve aspect ratio (iTerm2 only).widthCells(int cells) Set the display width in terminal cells.widthPixels(int pixels) Set the display width in pixels (iTerm2 and Sixel).
-
Method Details
-
builder
Create a builder that auto-detects the best image protocol for the device.- Parameters:
device- the terminal device- Returns:
- a new builder
-
builder
Create a builder using a specific image protocol.- Parameters:
protocol- the protocol to use- Returns:
- a new builder
-
detectProtocol
Detect the best image protocol for the given device.- Parameters:
device- the terminal device- Returns:
- the detected protocol, or NONE if no image support
-
file
Set the image data from a file.- Parameters:
path- path to the image file- Returns:
- this builder
- Throws:
IOException- if the file cannot be read
-
data
Set the image data from raw bytes.- Parameters:
data- the image data- Returns:
- this builder
-
filename
Set the filename (used by iTerm2 protocol).- Parameters:
filename- the filename- Returns:
- this builder
-
widthCells
Set the display width in terminal cells.- Parameters:
cells- number of cells- Returns:
- this builder
-
heightCells
Set the display height in terminal cells.- Parameters:
cells- number of cells- Returns:
- this builder
-
widthPixels
Set the display width in pixels (iTerm2 and Sixel).- Parameters:
pixels- width in pixels- Returns:
- this builder
-
heightPixels
Set the display height in pixels (iTerm2 and Sixel).- Parameters:
pixels- height in pixels- Returns:
- this builder
-
preserveAspectRatio
Set whether to preserve aspect ratio (iTerm2 only).- Parameters:
preserve- true to preserve aspect ratio- Returns:
- this builder
-
getProtocol
Get the protocol that will be used.- Returns:
- the image protocol
-
isSupported
public boolean isSupported()Check if image display is supported.- Returns:
- true if images can be displayed
-
build
Build the terminal image.- Returns:
- the terminal image, or null if protocol is NONE
- Throws:
IllegalStateException- if no image data has been set
-