Module terminal.cursor.position
Terminal cursor position module.
Provides utilities for cursor positioning in terminals.
Functions
backup () | Writes the ansi sequence to backup the current cursor position (in terminal storage, not stacked) to the terminal. |
column (column) | Moves the cursor to a column on the current row and writes it to the terminal. |
down ([n=1]) | Moves the cursor down and writes it to the terminal. |
get () | Requests the current cursor position from the terminal. |
horizontal ([n=1]) | Moves the cursor horizontally and writes it to the terminal. |
left ([n=1]) | Moves the cursor left and writes it to the terminal. |
move ([rows=0[, columns=0]]) | Moves the cursor horizontal and vertical and writes it to the terminal. |
query () | write the sequence for requesting cursor position, without flushing. |
restore () | Writes the ansi sequence to restore the cursor position (from the terminal storage, not stacked) to the terminal. |
right ([n=1]) | Moves the cursor right and writes it to the terminal. |
row (row) | Moves the cursor to a row on the current column and writes it to the terminal. |
set (row, column) | Sets the cursor position and writes it to the terminal. |
up ([n=1]) | Moves the cursor up and writes it to the terminal. |
vertical ([n=1]) | Moves the cursor vertically and writes it to the terminal. |
Sequences
backup_seq () | Returns the ansi sequence to backup the current cursor position (in terminal storage, not stacked). |
column_seq (column) | Creates an ansi sequence to move the cursor to a column on the current row without writing it to the terminal. |
down_seq ([n=1]) | Creates an ansi sequence to move the cursor down without writing it to the terminal. |
horizontal_seq ([n=1]) | Creates an ansi sequence to move the cursor horizontally without writing it to the terminal. |
left_seq ([n=1]) | Creates an ansi sequence to move the cursor left without writing it to the terminal. |
move_seq ([rows=0[, columns=0]]) | Creates an ansi sequence to move the cursor horizontal and vertical without writing it to the terminal. |
query_seq () | returns the sequence for requesting cursor position as a string. |
restore_seq () | Returns the ansi sequence to restore the cursor position (from the terminal storage, not stacked). |
right_seq ([n=1]) | Creates an ansi sequence to move the cursor right without writing it to the terminal. |
row_seq (row) | Creates an ansi sequence to move the cursor to a row on the current column without writing it to the terminal. |
set_seq (row, column) | Creates ansi sequence to set the cursor position without writing it to the terminal. |
up_seq ([n=1]) | Creates an ansi sequence to move the cursor up without writing it to the terminal. |
vertical_seq ([n=1]) | Creates an ansi sequence to move the cursor vertically without writing it to the terminal. |
Functions
- backup ()
-
Writes the ansi sequence to backup the current cursor position (in terminal storage, not stacked) to the terminal.
Returns:
-
true
- column (column)
-
Moves the cursor to a column on the current row and writes it to the terminal.
Parameters:
- column number the column to move to
Returns:
-
true
- down ([n=1])
-
Moves the cursor down and writes it to the terminal.
Parameters:
- n number number of rows to move down (default 1)
Returns:
-
true
- get ()
-
Requests the current cursor position from the terminal.
Will read entire keyboard buffer to empty it, then request the cursor position.
The output buffer will be flushed.
This function is relatively slow! It will block until the terminal responds. A least 1 sleep step will be executed, which is 20+ milliseconds usually (depends on the platform). So keeping track of the cursor is more efficient than calling this many times.
Returns:
- number row
- number column
Or
- nil
- string error message in case of a keyboard read error
- horizontal ([n=1])
-
Moves the cursor horizontally and writes it to the terminal.
Parameters:
- n number number of columns to move (negative for left, positive for right) (default 1)
Returns:
-
true
- left ([n=1])
-
Moves the cursor left and writes it to the terminal.
Parameters:
- n number number of columns to move left (default 1)
Returns:
-
true
- move ([rows=0[, columns=0]])
-
Moves the cursor horizontal and vertical and writes it to the terminal.
Parameters:
- rows number number of rows to move (negative for up, positive for down) (default 0)
- columns number number of columns to move (negative for left, positive for right) (default 0)
Returns:
-
true
- query ()
- write the sequence for requesting cursor position, without flushing. If you need to get the current position, use get instead.
- restore ()
-
Writes the ansi sequence to restore the cursor position (from the terminal storage, not stacked) to the terminal.
Returns:
-
true
- right ([n=1])
-
Moves the cursor right and writes it to the terminal.
Parameters:
- n number number of columns to move right (default 1)
Returns:
-
true
- row (row)
-
Moves the cursor to a row on the current column and writes it to the terminal.
Parameters:
- row number the row to move to
Returns:
-
true
- set (row, column)
-
Sets the cursor position and writes it to the terminal.
Parameters:
- row number
- column number
Returns:
-
true
- up ([n=1])
-
Moves the cursor up and writes it to the terminal.
Parameters:
- n number number of rows to move up (default 1)
Returns:
-
true
- vertical ([n=1])
-
Moves the cursor vertically and writes it to the terminal.
Parameters:
- n number number of rows to move (negative for up, positive for down) (default 1)
Returns:
-
true
Sequences
- backup_seq ()
-
Returns the ansi sequence to backup the current cursor position (in terminal storage, not stacked).
Returns:
-
string
ansi sequence to write to the terminal
- column_seq (column)
-
Creates an ansi sequence to move the cursor to a column on the current row without writing it to the terminal.
Parameters:
- column number the column to move to. Negative values are resolved from the right of the screen, such that -1 is the last column.
Returns:
-
string
ansi sequence to write to the terminal
- down_seq ([n=1])
-
Creates an ansi sequence to move the cursor down without writing it to the terminal.
Parameters:
- n number number of rows to move down (default 1)
Returns:
-
string
ansi sequence to write to the terminal
- horizontal_seq ([n=1])
-
Creates an ansi sequence to move the cursor horizontally without writing it to the terminal.
Parameters:
- n number number of columns to move (negative for left, positive for right) (default 1)
Returns:
-
string
ansi sequence to write to the terminal
- left_seq ([n=1])
-
Creates an ansi sequence to move the cursor left without writing it to the terminal.
Parameters:
- n number number of columns to move left (default 1)
Returns:
-
string
ansi sequence to write to the terminal
- move_seq ([rows=0[, columns=0]])
-
Creates an ansi sequence to move the cursor horizontal and vertical without writing it to the terminal.
Parameters:
- rows number number of rows to move (negative for up, positive for down) (default 0)
- columns number number of columns to move (negative for left, positive for right) (default 0)
Returns:
-
string
ansi sequence to write to the terminal
- query_seq ()
-
returns the sequence for requesting cursor position as a string.
If you need to get the current position, use get instead.
Returns:
-
string
the sequence for requesting cursor position
- restore_seq ()
-
Returns the ansi sequence to restore the cursor position (from the terminal storage, not stacked).
Returns:
-
string
ansi sequence to write to the terminal
- right_seq ([n=1])
-
Creates an ansi sequence to move the cursor right without writing it to the terminal.
Parameters:
- n number number of columns to move right (default 1)
Returns:
-
string
ansi sequence to write to the terminal
- row_seq (row)
-
Creates an ansi sequence to move the cursor to a row on the current column without writing it to the terminal.
Parameters:
- row number the row to move to. Negative values are resolved from the bottom of the screen, such that -1 is the last row.
Returns:
-
string
ansi sequence to write to the terminal
- set_seq (row, column)
-
Creates ansi sequence to set the cursor position without writing it to the terminal.
Parameters:
- row number the new row. Negative values are resolved from the bottom of the screen, such that -1 is the last row.
- column number the new column. Negative values are resolved from the right of the screen, such that -1 is the last column.
Returns:
-
string
ansi sequence to write to the terminal
- up_seq ([n=1])
-
Creates an ansi sequence to move the cursor up without writing it to the terminal.
Parameters:
- n number number of rows to move up (default 1)
Returns:
-
string
ansi sequence to write to the terminal
- vertical_seq ([n=1])
-
Creates an ansi sequence to move the cursor vertically without writing it to the terminal.
Parameters:
- n number number of rows to move (negative for up, positive for down) (default 1)
Returns:
-
string
ansi sequence to write to the terminal