Package org.jline.terminal


package org.jline.terminal
JLine Terminal API - Core abstractions for terminal operations across different platforms.

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 terminal
  • MouseEvent - 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