Class Cursor

java.lang.Object
org.jline.terminal.Cursor

public class Cursor extends Object
Represents the position of the cursor within a terminal.

The Cursor class encapsulates the coordinates of the cursor in a terminal, providing access to its X (column) and Y (row) position. Cursor positions are used for various terminal operations such as text insertion, deletion, and formatting.

In terminal coordinates:

  • X coordinate - Represents the column position (horizontal), typically 0-based
  • Y coordinate - Represents the row position (vertical), typically 0-based

Cursor objects are typically obtained from a Terminal using the Terminal.getCursorPosition(java.util.function.IntConsumer) method, which queries the terminal for its current cursor position. This information can be used to determine where text will be inserted or to calculate relative positions for cursor movement.

Example usage:

 Terminal terminal = TerminalBuilder.terminal();

 // Get current cursor position
 Cursor cursor = terminal.getCursorPosition(c -> {});
 if (cursor != null) {
     System.out.println("Cursor position: column=" + cursor.getX() + ", row=" + cursor.getY());
 }
 

Note that not all terminals support cursor position reporting. The Terminal.getCursorPosition(java.util.function.IntConsumer) method may return null if cursor position reporting is not supported.

See Also: