2022-01-21 08:28:41 +00:00
|
|
|
'use strict';
|
|
|
|
const restoreCursor = require('restore-cursor');
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
let hidden = false;
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
exports.show = stream => {
|
|
|
|
const s = stream || process.stderr;
|
|
|
|
|
|
|
|
if (!s.isTTY) {
|
2022-01-21 08:28:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
hidden = false;
|
|
|
|
s.write('\u001b[?25h');
|
2022-01-21 08:28:41 +00:00
|
|
|
};
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
exports.hide = stream => {
|
|
|
|
const s = stream || process.stderr;
|
|
|
|
|
|
|
|
if (!s.isTTY) {
|
2022-01-21 08:28:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
restoreCursor();
|
2022-05-29 09:24:36 +00:00
|
|
|
hidden = true;
|
|
|
|
s.write('\u001b[?25l');
|
2022-01-21 08:28:41 +00:00
|
|
|
};
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
exports.toggle = (force, stream) => {
|
2022-01-21 08:28:41 +00:00
|
|
|
if (force !== undefined) {
|
2022-05-29 09:24:36 +00:00
|
|
|
hidden = force;
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
if (hidden) {
|
|
|
|
exports.show(stream);
|
2022-01-21 08:28:41 +00:00
|
|
|
} else {
|
2022-05-29 09:24:36 +00:00
|
|
|
exports.hide(stream);
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
};
|