chuwanghui 6d115466a5 electron库 | 6 years ago | |
---|---|---|
.. | ||
.npmignore | 6 years ago | |
LICENSE | 6 years ago | |
README.md | 6 years ago | |
index.js | 6 years ago | |
package.json | 6 years ago | |
test.js | 6 years ago |
Node.js module that keeps writing to the same line in the console (or a stream). Very useful when you write progress bars, or a status message during longer operations. Supports multilines.
npm install single-line-log
var log = require('single-line-log').stdout;
// or pass any stream:
// var log = require('single-line-log')(process.stdout);
var read = 0;
var size = fs.statSync('super-large-file').size;
var rs = fs.createReadStream('super-large-file');
rs.on('data', function(data) {
read += data.length;
var percentage = Math.floor(100*read/size);
// Keep writing to the same two lines in the console
log('Writing to super large file\n[' + percentage + '%]', read, 'bytes read');
});
Clears the log (i.e., writes a newline).
var log = require('single-line-log').stdout;
log('Line 1');
log.clear();
log('Line 2');
Outputs to process.stdout
.
Outputs to process.stderr
.
MIT