Class CursorSupport


  • public class CursorSupport
    extends java.lang.Object
    Utility class for cursor position detection in terminals.

    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:

    1. Sending a special escape sequence to the terminal (defined by user7 capability)
    2. Reading the terminal's response
    3. Parsing the response using a pattern derived from the user6 capability
    4. 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:
    Terminal.getCursorPosition(IntConsumer), Cursor
    • Constructor Summary

      Constructors 
      Constructor Description
      CursorSupport()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Cursor getCursorPosition​(Terminal terminal, java.util.function.IntConsumer discarded)
      Gets the current cursor position from the terminal.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CursorSupport

        public CursorSupport()
    • Method Detail

      • getCursorPosition

        public static Cursor getCursorPosition​(Terminal terminal,
                                               java.util.function.IntConsumer discarded)
        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 from
        discarded - 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)