pax_global_header00006660000000000000000000000064127644451140014522gustar00rootroot0000000000000052 comment=515b3b99b699396c2ad5f937e4b490b6f9fbff0e single-line-log-1.1.2/000077500000000000000000000000001276444511400145105ustar00rootroot00000000000000single-line-log-1.1.2/.gitignore000066400000000000000000000000141276444511400164730ustar00rootroot00000000000000node_modulessingle-line-log-1.1.2/LICENSE000066400000000000000000000021111276444511400155100ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Tobias Baunbæk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. single-line-log-1.1.2/README.md000066400000000000000000000017701276444511400157740ustar00rootroot00000000000000# single-line-log 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. ## Installation npm install single-line-log ## Usage ``` js 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'); }); ``` ## .clear() Clears the log (i.e., writes a newline). ``` js var log = require('single-line-log').stdout; log('Line 1'); log.clear(); log('Line 2'); ``` ## .stdout Outputs to `process.stdout`. ## .stderr Outputs to `process.stderr`. ## License MITsingle-line-log-1.1.2/index.js000066400000000000000000000024271276444511400161620ustar00rootroot00000000000000var MOVE_LEFT = new Buffer('1b5b3130303044', 'hex').toString(); var MOVE_UP = new Buffer('1b5b3141', 'hex').toString(); var CLEAR_LINE = new Buffer('1b5b304b', 'hex').toString(); var stringWidth = require('string-width'); module.exports = function(stream) { var write = stream.write; var str; stream.write = function(data) { if (str && data !== str) str = null; return write.apply(this, arguments); }; if (stream === process.stderr || stream === process.stdout) { process.on('exit', function() { if (str !== null) stream.write(''); }); } var prevLineCount = 0; var log = function() { str = ''; var nextStr = Array.prototype.join.call(arguments, ' '); // Clear screen for (var i=0; i", "dependencies": { "string-width": "^1.0.1" }, "scripts": { "test": "node test.js" } } single-line-log-1.1.2/test.js000066400000000000000000000006141276444511400160260ustar00rootroot00000000000000var log = require('./index').stdout; var i = 0; setInterval(function() { i++; var s = 'line 1 - ' + Math.random(); if (i < 10) s += ' - ' + Math.random(); if (i < 40) s += '\nline 2 - ' + Math.random(); if (i < 30) s += '\nline 3 - ' + Math.random(); if (i < 20) s += '\nline 4 - ' + Math.random(); log(s); if (i === 50) { log.clear(); process.exit(0); } }, 200);