index.js 671 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var ansiEscapes = require('ansi-escapes');
  3. var cliCursor = require('cli-cursor');
  4. function main(stream) {
  5. var prevLineCount = 0;
  6. var render = function () {
  7. cliCursor.hide();
  8. var out = [].join.call(arguments, ' ') + '\n';
  9. stream.write(ansiEscapes.eraseLines(prevLineCount) + out);
  10. prevLineCount = out.split('\n').length;
  11. };
  12. render.clear = function () {
  13. stream.write(ansiEscapes.eraseLines(prevLineCount));
  14. prevLineCount = 0;
  15. };
  16. render.done = function () {
  17. prevLineCount = 0;
  18. cliCursor.show();
  19. };
  20. return render;
  21. }
  22. module.exports = main(process.stdout);
  23. module.exports.stderr = main(process.stderr);
  24. module.exports.create = main;