Package org.jline.terminal
This package provides a comprehensive API for interacting with terminals in a platform-independent way. It abstracts the differences between various terminal types and operating systems, allowing applications to work consistently across environments.
Key Components
Terminal Interface
The Terminal
interface is the central abstraction, representing a virtual
terminal. It provides methods for:
- Reading input and writing output
- Managing terminal attributes
- Handling terminal size and cursor positioning
- Processing signals (like CTRL+C)
- Supporting mouse events
- Accessing terminal capabilities
Terminal Creation
The TerminalBuilder
class provides a fluent API for creating terminal
instances with specific configurations. It supports various terminal types and providers, allowing
for flexible terminal creation based on the environment and requirements.
Terminal Attributes
The Attributes
class encapsulates terminal settings such as:
- Input flags (e.g., character echoing, canonical mode)
- Output flags (e.g., output processing)
- Control flags (e.g., baud rate, character size)
- Local flags (e.g., echo, canonical processing)
- Control characters (e.g., EOF, interrupt, erase)
Supporting Classes
Size
- Represents the dimensions of a terminal (rows and columns)Cursor
- Represents a cursor position within the terminalMouseEvent
- Encapsulates mouse events (clicks, movements) in the terminal
Usage Example
// Create a terminal Terminal terminal = TerminalBuilder.builder() .system(true) .build(); // Get terminal size Size size = terminal.getSize(); System.out.println("Terminal size: " + size.getColumns() + "x" + size.getRows()); // Write to the terminal terminal.writer().println("Hello, JLine Terminal!"); terminal.flush(); // Read from the terminal int c = terminal.reader().read(); // Close the terminal when done terminal.close();
Terminal Implementations
The actual terminal implementations are provided in the org.jline.terminal.impl
package,
with platform-specific implementations available through various provider modules like:
- jline-terminal-ffm - Foreign Function & Memory (Java 22+) based implementation
- jline-terminal-jni - JNI-based implementation
- jline-terminal-jansi - JANSI-based implementation
- jline-terminal-jna - JNA-based implementation
The Service Provider Interface (SPI) for terminal implementations is defined in the
org.jline.terminal.spi
package.
- Since:
- 3.0
-
Interface Summary Interface Description Terminal A terminal representing a virtual terminal on the computer.Terminal.SignalHandler Interface for handling terminal signals. -
Class Summary Class Description Attributes Encapsulates terminal attributes and settings that control terminal behavior.Cursor Represents the position of the cursor within a terminal.MouseEvent Represents a mouse event in a terminal that supports mouse tracking.Size Represents the dimensions of a terminal in terms of rows and columns.TerminalBuilder Builder class to createTerminal
instances with flexible configuration options. -
Enum Summary Enum Description Attributes.ControlChar Control characters used for special terminal functions.Attributes.ControlFlag Control flags that manage hardware aspects of the terminal.Attributes.InputFlag Input flags that control how terminal input is processed.Attributes.LocalFlag Local flags that control various terminal behaviors.Attributes.OutputFlag Output flags that control how terminal output is processed.MouseEvent.Button Defines the mouse buttons that can be involved in a mouse event.MouseEvent.Modifier Defines the modifier keys that can be pressed during a mouse event.MouseEvent.Type Defines the types of mouse events that can occur.Terminal.MouseTracking Terminal.Signal Types of signals that can be handled by terminal applications.TerminalBuilder.SystemOutput