Comprehensive cursor control operations for precise terminal positioning, relative movement, and visibility management.
Set the absolute position of the cursor on the terminal screen.
/**
* Set the absolute position of the cursor. (0,0) is the top left of the screen.
* @param x - Column position (required)
* @param y - Row position (optional, if omitted cursor moves to column x on current row)
* @returns ANSI escape sequence string
*/
function cursorTo(x: number, y?: number): string;Usage Examples:
import { cursorTo } from 'ansi-escapes';
// Move to column 10 on current row
process.stdout.write(cursorTo(10));
// Move to position (5, 3) - column 5, row 3
process.stdout.write(cursorTo(5, 3));
// Move to top-left corner
process.stdout.write(cursorTo(0, 0));Move the cursor relative to its current position.
/**
* Set the position of the cursor relative to its current position
* @param x - Horizontal offset (negative for left, positive for right)
* @param y - Vertical offset (optional, negative for up, positive for down)
* @returns ANSI escape sequence string
*/
function cursorMove(x: number, y?: number): string;Usage Examples:
import { cursorMove } from 'ansi-escapes';
// Move 5 positions right
process.stdout.write(cursorMove(5));
// Move 3 positions left, 2 positions up
process.stdout.write(cursorMove(-3, -2));
// Move 10 positions right, 1 position down
process.stdout.write(cursorMove(10, 1));Move cursor in specific directions by specified amounts.
/**
* Move cursor up a specific amount of rows
* @param count - Number of rows to move up (default: 1)
* @returns ANSI escape sequence string
*/
function cursorUp(count?: number): string;
/**
* Move cursor down a specific amount of rows
* @param count - Number of rows to move down (default: 1)
* @returns ANSI escape sequence string
*/
function cursorDown(count?: number): string;
/**
* Move cursor forward (right) a specific amount of columns
* @param count - Number of columns to move forward (default: 1)
* @returns ANSI escape sequence string
*/
function cursorForward(count?: number): string;
/**
* Move cursor backward (left) a specific amount of columns
* @param count - Number of columns to move backward (default: 1)
* @returns ANSI escape sequence string
*/
function cursorBackward(count?: number): string;Usage Examples:
import { cursorUp, cursorDown, cursorForward, cursorBackward } from 'ansi-escapes';
// Move cursor up 1 row (default)
process.stdout.write(cursorUp());
// Move cursor up 5 rows
process.stdout.write(cursorUp(5));
// Move cursor down 2 rows
process.stdout.write(cursorDown(2));
// Move cursor right 10 columns
process.stdout.write(cursorForward(10));
// Move cursor left 3 columns
process.stdout.write(cursorBackward(3));Pre-defined cursor positioning operations.
/**
* Move cursor to the left side of the terminal
*/
const cursorLeft: string;
/**
* Move cursor to the next line
*/
const cursorNextLine: string;
/**
* Move cursor to the previous line
*/
const cursorPrevLine: string;Usage Examples:
import { cursorLeft, cursorNextLine, cursorPrevLine } from 'ansi-escapes';
// Move to beginning of current line
process.stdout.write(cursorLeft);
// Move to beginning of next line
process.stdout.write(cursorNextLine);
// Move to beginning of previous line
process.stdout.write(cursorPrevLine);Save and restore cursor positions for complex terminal operations.
/**
* Save the current cursor position
*/
const cursorSavePosition: string;
/**
* Restore the previously saved cursor position
*/
const cursorRestorePosition: string;
/**
* Get the current cursor position (returns as terminal response)
*/
const cursorGetPosition: string;Usage Examples:
import { cursorSavePosition, cursorRestorePosition, cursorGetPosition } from 'ansi-escapes';
// Save current position
process.stdout.write(cursorSavePosition);
// ... do some operations that move the cursor ...
// Restore to saved position
process.stdout.write(cursorRestorePosition);
// Request current cursor position (terminal will respond via stdin)
process.stdout.write(cursorGetPosition);Control cursor visibility on the terminal.
/**
* Hide the cursor
*/
const cursorHide: string;
/**
* Show the cursor
*/
const cursorShow: string;Usage Examples:
import { cursorHide, cursorShow } from 'ansi-escapes';
// Hide cursor during terminal updates
process.stdout.write(cursorHide);
// ... perform terminal operations ...
// Show cursor when done
process.stdout.write(cursorShow);