askForCursorPositionSync

import { askForCursorPositionSync } from "jsr:@ende/cli/unstable-get-cursor";

function ยท experimental

function askForCursorPositionSync(): { row: number; column: number } | null

This function asks the terminal for the cursor's current position. Information entered by the user will be discarded while requesting the cursor position. The cursor position may have also moved in this time due to the user entering information. Due to the sync nature of this function, it is not recommended to use this function frequently. Instead Ansi.SAVE_CURSOR and Ansi.RESTORE_CURSOR should be used when possible.

Returns

The cursor position or null if the terminal is not a TTY.

Example: Usage

import * as Ansi from "@ende/cli/unstable-ansi";
import { askForCursorPositionSync } from "@ende/cli/unstable-get-cursor";

const { column, row } = askForCursorPositionSync()!;
await Ende.stderr.write(new TextEncoder().encode(
  Ansi.setCursorPosition() +
    "Hello World!" +
    Ansi.setCursorPosition(row, column),
));

Source