wishthis/node_modules/cli-cursor/index.js

36 lines
617 B
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
'use strict';
const restoreCursor = require('restore-cursor');
2022-04-07 07:06:43 +00:00
let isHidden = false;
2022-01-21 08:28:41 +00:00
2022-04-07 07:06:43 +00:00
exports.show = (writableStream = process.stderr) => {
if (!writableStream.isTTY) {
2022-01-21 08:28:41 +00:00
return;
}
2022-04-07 07:06:43 +00:00
isHidden = false;
writableStream.write('\u001B[?25h');
2022-01-21 08:28:41 +00:00
};
2022-04-07 07:06:43 +00:00
exports.hide = (writableStream = process.stderr) => {
if (!writableStream.isTTY) {
2022-01-21 08:28:41 +00:00
return;
}
restoreCursor();
2022-04-07 07:06:43 +00:00
isHidden = true;
writableStream.write('\u001B[?25l');
2022-01-21 08:28:41 +00:00
};
2022-04-07 07:06:43 +00:00
exports.toggle = (force, writableStream) => {
2022-01-21 08:28:41 +00:00
if (force !== undefined) {
2022-04-07 07:06:43 +00:00
isHidden = force;
2022-01-21 08:28:41 +00:00
}
2022-04-07 07:06:43 +00:00
if (isHidden) {
exports.show(writableStream);
2022-01-21 08:28:41 +00:00
} else {
2022-04-07 07:06:43 +00:00
exports.hide(writableStream);
2022-01-21 08:28:41 +00:00
}
};