Class Cursor
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:
-
Constructor Summary
ConstructorsConstructorDescriptionCursor
(int x, int y) Creates a new Cursor instance at the specified coordinates. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compares this Cursor object with another object for equality.int
getX()
Returns the column position (horizontal coordinate) of this cursor.int
getY()
Returns the row position (vertical coordinate) of this cursor.int
hashCode()
Returns a hash code for this Cursor object.toString()
Returns a string representation of this Cursor object.
-
Constructor Details
-
Cursor
public Cursor(int x, int y) Creates a new Cursor instance at the specified coordinates.This constructor creates a Cursor object representing a position in the terminal at the given column (x) and row (y) coordinates. In terminal coordinates, the origin (0,0) is typically at the top-left corner of the screen.
- Parameters:
x
- the column position (horizontal coordinate)y
- the row position (vertical coordinate)
-
-
Method Details
-
getX
public int getX()Returns the column position (horizontal coordinate) of this cursor.The X coordinate represents the horizontal position of the cursor in the terminal, measured in character cells from the left edge of the terminal. The leftmost column is typically position 0.
- Returns:
- the column position (X coordinate)
-
getY
public int getY()Returns the row position (vertical coordinate) of this cursor.The Y coordinate represents the vertical position of the cursor in the terminal, measured in character cells from the top edge of the terminal. The topmost row is typically position 0.
- Returns:
- the row position (Y coordinate)
-
equals
Compares this Cursor object with another object for equality.Two Cursor objects are considered equal if they have the same X and Y coordinates.
-
hashCode
public int hashCode()Returns a hash code for this Cursor object.The hash code is computed based on the X and Y coordinates.
-
toString
Returns a string representation of this Cursor object.The string representation includes the X and Y coordinates.
-