An ANSI escape codes library for Deno.
Cursor object.
const cursor: {...}
Moves the cursor to the top left corner of the terminal.
function home() : Promise<void>
await cursor.home();
Moves the cursor to a specific position in the terminal. The index starts from 0.
If the position is positive outside the terminal, then the cursor is placed in the bottom right corner.
If the position is negative outside the terminal, then the cursor is placed in the top left corner.
function moveTo(position : cursorPosition) : Promise<void>
// Moves the cursor to the 10th row and to the 20th column.
await cursor.moveTo({row: 9, column: 19});
Moves the cursor a specified amount of rows up. The position in the column remains the same.
If the number is greater than the cursor can move up, then the cursor gets moved all the way up.
function moveUp(amount? : number) : Promise<void>
// Moves the cursor 5 rows up.
await cursor.moveUp(5);
Moves the cursor a specified amount of rows down. The position in the column remains the same.
If the number is greater than the cursor can move down, then the cursor gets moved all the way down.
function moveDown(amount? : number) : Promise<void>
// Moves the cursor 7 rows down.
await cursor.moveDown(7);
Moves the cursor a specified amount of columns to the right. The position in the row remains the same.
If the number is greater than the cursor can move to the right, then the cursor gets moved all the way to the right side.
function moveRight(amount? : number) : Promise<void>
// Moves the cursor 3 columns to the right.
await cursor.moveRight(3);
Moves the cursor a specified amount of columns to the left. The position in the row remains the same.
If the number is greater than the cursor can move to the left, then the cursor gets moved all the way to the left side.
function moveLeft(amount? : number) : Promise<void>
// Moves the cursor 6 columns to the left.
await cursor.moveLeft(6);
Moves the cursor a specified amount of rows down. The position in the column is reset to the start.
If the number is greater than the cursor can move down, then the cursor gets moved all the way down.
function moveDownStart(amount? : number) : Promise<void>
// Moves the cursor 2 rows down.
await cursor.moveDownStart(2);
Moves the cursor a specified amount of columns up. The position in the column is reset to the start.
If the number is greater than the cursor can move up, then the cursor gets moved all the way up.
function moveUpStart(amount? : number) : Promise<void>
// Moves the cursor 2 rows up.
await cursor.moveUpStart(2);
Sets the cursor to an absolute position in the column. The position in the row remains the same.
If the absolute position is positive outside the terminal, then the cursor is set to the right side. If the absolute position is negative outside the terminal, then the cursor is set to the left side.
function moveToColumn(to : number) : Promise<void>
// Sets the cursor to the 9th absolute column.
await cursor.moveToColumn(9);
Get the current absolute position of the cursor.
function getPosition() : Promise<cursorPosition>
// Get the absolut cursor position.
const position = await cursor.getPosition();
// Log the row and column position
console.log(`Row: ${position.row}, Column: ${position.column}`);
Save the current absolute position of the cursor.
The position is stored internally. Only one position can be saved at a time.
function savePosition() : Promise<void>
await cursor.savePosition();
Restore the currently saved absolute position of the cursor.
function restorePosition() : Promise<void>
await cursor.restorePosition();
Show the cursor.
function show() : Promise<void>
await cursor.show();
Hide the cursor.
function hide() : Promise<void>
await cursor.hide();