index.js 617 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const restoreCursor = require('restore-cursor');
  3. let isHidden = false;
  4. exports.show = (writableStream = process.stderr) => {
  5. if (!writableStream.isTTY) {
  6. return;
  7. }
  8. isHidden = false;
  9. writableStream.write('\u001B[?25h');
  10. };
  11. exports.hide = (writableStream = process.stderr) => {
  12. if (!writableStream.isTTY) {
  13. return;
  14. }
  15. restoreCursor();
  16. isHidden = true;
  17. writableStream.write('\u001B[?25l');
  18. };
  19. exports.toggle = (force, writableStream) => {
  20. if (force !== undefined) {
  21. isHidden = force;
  22. }
  23. if (isHidden) {
  24. exports.show(writableStream);
  25. } else {
  26. exports.hide(writableStream);
  27. }
  28. };