Terminal Cursor

The Cursor is the position where the user types and it is represented by a Caret.

As the Cursor is a position. It is composed by:

  • line Number: the number of the line where the Cursor is located.

  • column Number: the number of the column where the Cursor is located.

It is important to understand that the Caret is the visual representation of the Cursor and it is only visible when the Terminal is focused.

moveTerminalCursor

Moves the Cursor to a different position.

The Cursor can be moved in three different ways:

  • to a specific position.

  • by offset.

  • to a specific position and then by offset.

Note: Dispatches an action with the type @orion/terminals-helper/MOVE_TERMINAL_CURSOR which can be handled
Usage
Copy
dispatchersHelper.dispatch('moveTerminalCursor', {
  terminalId: String,
  to: Position,
  offset: Object,
});
  • terminalId String

    Required. The ID of the Terminal.

  • to Position

  • Optional. The position where the Cursor will be moved.

  • line Number | "first" | "last"

    Optional. The number of the line where the Cursor will be located.

  • column Number | "first" | "last" | "lastChar" | "afterLastChar"

    Optional. The number of the column where the Cursor will be located.

  • offset String

    Optional. An offset to determine how many columns or lines the Cursor will be moved.

  • lines Number

    Optional. The number of lines the Cursor will be moved to the top (negative) or to the bottom (positive).

  • columns Number

    Optional. The number of columns the Cursor will be moved to the left (negative) or to the right (positive).

 

getTerminalCursorPosition

Retrieves the current position of the Cursor.

Copy
getTerminalCursorPosition(state: Object, { terminalId: String }): Position;
  • state Object

    Required. The global state of the application.

  • terminalId String

    Required. The ID of the Terminal to retrieve its Cursor position.

Returns
  • Position

    The current position of the Cursor.

  • line Number

    The number of the line where the Cursor is located.

  • column Number

    The number of the column where the Cursor is located.

Example
Copy
const state = storeHelper.getState();
const getTerminalCursorPosition = selectorsHelper.make('getTerminalCursorPosition');
const cursorPosition = getTerminalCursorPosition(state, { terminalId });
const { line, column } = cursorPosition;