MCPcopy Create free account
hub / github.com/denoland/std / askForCursorPositionSync

Function askForCursorPositionSync

cli/unstable_get_cursor.ts:26–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24 * ```
25 */
26export function askForCursorPositionSync():
27 | { row: number; column: number }
28 | null {
29 if (!Deno.stdin.isTerminal() || !Deno.stderr.isTerminal()) {
30 return null;
31 }
32 Deno.stdin.setRaw(true, { cbreak: true });
33 Deno.stderr.writeSync(Uint8Array.from([0x1b, 0x5b, 0x36, 0x6e])); // \x1b[6n
34 const buffer = new Uint8Array(1024);
35 while (true) {
36 const x = Deno.stdin.readSync(buffer.subarray(32));
37 const csi = findCSI(buffer.subarray(0, 32 + x!));
38 if (csi?.final === 82) { // R
39 Deno.stdin.setRaw(false);
40 const [row, column] = new TextDecoder()
41 .decode(csi.parameters)
42 .split(";")
43 .map((x) => parseInt(x));
44 return { row: row!, column: column! };
45 }
46 buffer.set(buffer.subarray(buffer.length - 32));
47 }
48}
49
50function findCSI(
51 buffer: Uint8Array,

Callers

nothing calls this directly

Calls 7

findCSIFunction · 0.85
isTerminalMethod · 0.65
setRawMethod · 0.65
writeSyncMethod · 0.65
readSyncMethod · 0.65
setMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected