@wocker/ws
Version:
Docker workspace for web projects
28 lines (27 loc) • 945 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCursorPosition = void 0;
const code = "\x1b[6n";
const getCursorPosition = async () => {
process.stdin.resume();
process.stdin.setRawMode(true);
const position = {};
await new Promise((resolve, reject) => {
const handleData = (data) => {
const match = /\[(\d+);(\d+)R$/.exec(data.toString());
if (match) {
const [, col, row] = match.slice(1, 3).reverse().map(Number);
position.row = row;
position.col = col;
resolve(undefined);
}
process.stdin.off("data", handleData);
process.stdin.pause();
};
process.stdin.once("data", handleData);
process.stdout.write(code);
process.stdout.emit("data", code);
});
return position;
};
exports.getCursorPosition = getCursorPosition;