securityos/node_modules/cli-cursor/index.js

40 lines
694 B
JavaScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
import process from 'node:process';
import restoreCursor from 'restore-cursor';
let isHidden = false;
const cliCursor = {};
cliCursor.show = (writableStream = process.stderr) => {
if (!writableStream.isTTY) {
return;
}
isHidden = false;
writableStream.write('\u001B[?25h');
};
cliCursor.hide = (writableStream = process.stderr) => {
if (!writableStream.isTTY) {
return;
}
restoreCursor();
isHidden = true;
writableStream.write('\u001B[?25l');
};
cliCursor.toggle = (force, writableStream) => {
if (force !== undefined) {
isHidden = force;
}
if (isHidden) {
cliCursor.show(writableStream);
} else {
cliCursor.hide(writableStream);
}
};
export default cliCursor;