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 invalid input: '&' 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
-
ClassDescriptionEncapsulates terminal attributes and settings that control terminal behavior.Control characters used for special terminal functions.Control flags that manage hardware aspects of the terminal.Input flags that control how terminal input is processed.Local flags that control various terminal behaviors.Output flags that control how terminal output is processed.Represents the position of the cursor within a terminal.Represents a mouse event in a terminal that supports mouse tracking.Defines the mouse buttons that can be involved in a mouse event.Defines the modifier keys that can be pressed during a mouse event.Defines the types of mouse events that can occur.Represents the dimensions of a terminal in terms of rows and columns.A terminal representing a virtual terminal on the computer.Types of signals that can be handled by terminal applications.Interface for handling terminal signals.Builder class to create
Terminal
instances with flexible configuration options.