Class CursorSupport
The CursorSupport class provides functionality for determining the current cursor position in a terminal. It uses terminal capabilities to request the cursor position from the terminal and parse the response.
This class is used internally by terminal implementations to implement the
Terminal.getCursorPosition(IntConsumer)
method. It relies on specific
terminal capabilities (user6 and user7) that define the sequence to request
the cursor position and the format of the response.
The cursor position detection works by:
- Sending a special escape sequence to the terminal (defined by user7 capability)
- Reading the terminal's response
- Parsing the response using a pattern derived from the user6 capability
- Extracting the row and column coordinates from the parsed response
Note that cursor position reporting is not supported by all terminals, and this method may return null if the terminal does not support this feature or if an error occurs during the detection process.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Cursor
getCursorPosition
(Terminal terminal, IntConsumer discarded) Gets the current cursor position from the terminal.
-
Constructor Details
-
CursorSupport
public CursorSupport()
-
-
Method Details
-
getCursorPosition
Gets the current cursor position from the terminal.This method sends a request to the terminal for its current cursor position and parses the response to extract the coordinates. It uses the terminal's user6 and user7 capabilities to determine the request sequence and response format.
The method reads from the terminal's input stream until it finds a response that matches the expected pattern. Any characters read that are not part of the cursor position response can be optionally collected through the discarded consumer.
- Parameters:
terminal
- the terminal to get the cursor position fromdiscarded
- an optional consumer for characters read that are not part of the cursor position response, or null if these characters should be ignored- Returns:
- the cursor position, or null if the position could not be determined (e.g., if the terminal does not support cursor position reporting)
-