UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Cursor = void 0;
4const tslib_1 = require("tslib");
5const signal_exit_1 = tslib_1.__importDefault(require("signal-exit"));
6const ansi_1 = require("./ansi");
7class Cursor {
8 static show() {
9 if (Cursor.stream.isTTY) {
10 Cursor._isVisible = true;
11 Cursor.stream.write(ansi_1.EscapeCode.cursorShow());
12 }
13 }
14 static hide() {
15 if (Cursor.stream.isTTY) {
16 if (!Cursor._listenerAttached) {
17 (0, signal_exit_1.default)(() => {
18 Cursor.show();
19 });
20 Cursor._listenerAttached = true;
21 }
22 Cursor._isVisible = false;
23 Cursor.stream.write(ansi_1.EscapeCode.cursorHide());
24 }
25 }
26 static toggle() {
27 if (Cursor._isVisible) {
28 Cursor.hide();
29 }
30 else {
31 Cursor.show();
32 }
33 }
34}
35exports.Cursor = Cursor;
36Cursor.stream = process.stderr;
37Cursor._isVisible = true;
38Cursor._listenerAttached = false;