-
-
Notifications
You must be signed in to change notification settings - Fork 615
/
log-update.js
39 lines (30 loc) · 942 Bytes
/
log-update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Fork of `log-update` without `wrap-ansi` until https://github.com/chalk/wrap-ansi/issues/27 is closed
'use strict';
const ansiEscapes = require('ansi-escapes');
const cliCursor = require('cli-cursor');
const main = (stream, options) => {
options = {showCursor: false, ...options};
let prevLineCount = 0;
const render = function () {
if (!options.showCursor) {
cliCursor.hide();
}
const out = [].join.call(arguments, ' ') + '\n'; // eslint-disable-line prefer-rest-params
stream.write(ansiEscapes.eraseLines(prevLineCount) + out);
prevLineCount = out.split('\n').length;
};
render.clear = () => {
stream.write(ansiEscapes.eraseLines(prevLineCount));
prevLineCount = 0;
};
render.done = () => {
prevLineCount = 0;
if (!options.showCursor) {
cliCursor.show();
}
};
return render;
};
module.exports = main(process.stdout);
module.exports.stderr = main(process.stderr);
module.exports.create = main;