diff options
| author | Arman Shah <[email protected]> | 2018-02-19 23:50:04 -0800 |
|---|---|---|
| committer | Arman Shah <[email protected]> | 2018-02-19 23:50:04 -0800 |
| commit | ae34dcfd3823a609ba7182f2d6eda593be876f7d (patch) | |
| tree | b9d7f2884c4999349418cbdc4f9ab46d113e0afd /node_modules/single-line-log | |
| parent | Initial commit (diff) | |
| download | launcher-ae34dcfd3823a609ba7182f2d6eda593be876f7d.tar.xz launcher-ae34dcfd3823a609ba7182f2d6eda593be876f7d.zip | |
add base files
Diffstat (limited to 'node_modules/single-line-log')
| -rw-r--r-- | node_modules/single-line-log/.npmignore | 1 | ||||
| -rw-r--r-- | node_modules/single-line-log/LICENSE | 21 | ||||
| -rw-r--r-- | node_modules/single-line-log/README.md | 56 | ||||
| -rw-r--r-- | node_modules/single-line-log/index.js | 51 | ||||
| -rw-r--r-- | node_modules/single-line-log/package.json | 62 | ||||
| -rw-r--r-- | node_modules/single-line-log/test.js | 21 |
6 files changed, 212 insertions, 0 deletions
diff --git a/node_modules/single-line-log/.npmignore b/node_modules/single-line-log/.npmignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/node_modules/single-line-log/.npmignore @@ -0,0 +1 @@ +node_modules
\ No newline at end of file diff --git a/node_modules/single-line-log/LICENSE b/node_modules/single-line-log/LICENSE new file mode 100644 index 0000000..57dffb7 --- /dev/null +++ b/node_modules/single-line-log/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Tobias Baunbæk <[email protected]> + +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. diff --git a/node_modules/single-line-log/README.md b/node_modules/single-line-log/README.md new file mode 100644 index 0000000..f142e30 --- /dev/null +++ b/node_modules/single-line-log/README.md @@ -0,0 +1,56 @@ +# 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 + +MIT
\ No newline at end of file diff --git a/node_modules/single-line-log/index.js b/node_modules/single-line-log/index.js new file mode 100644 index 0000000..c1201be --- /dev/null +++ b/node_modules/single-line-log/index.js @@ -0,0 +1,51 @@ +var 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<prevLineCount; i++) { + str += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount-1 ? MOVE_UP : ''); + } + + // Actual log output + str += nextStr; + stream.write(str); + + // How many lines to remove on next clear screen + var prevLines = nextStr.split('\n'); + prevLineCount = 0; + for (var i=0; i < prevLines.length; i++) { + prevLineCount += Math.ceil(stringWidth(prevLines[i]) / stream.columns) || 1; + } + }; + + log.clear = function() { + stream.write(''); + }; + + return log; +}; + +module.exports.stdout = module.exports(process.stdout); +module.exports.stderr = module.exports(process.stderr); diff --git a/node_modules/single-line-log/package.json b/node_modules/single-line-log/package.json new file mode 100644 index 0000000..7b4f1a9 --- /dev/null +++ b/node_modules/single-line-log/package.json @@ -0,0 +1,62 @@ +{ + "_from": "single-line-log@^1.1.2", + "_id": "[email protected]", + "_inBundle": false, + "_integrity": "sha1-wvg/Jzo+GhbtsJlWYdoO1e8DM2Q=", + "_location": "/single-line-log", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "single-line-log@^1.1.2", + "name": "single-line-log", + "escapedName": "single-line-log", + "rawSpec": "^1.1.2", + "saveSpec": null, + "fetchSpec": "^1.1.2" + }, + "_requiredBy": [ + "/nugget" + ], + "_resolved": "https://registry.npmjs.org/single-line-log/-/single-line-log-1.1.2.tgz", + "_shasum": "c2f83f273a3e1a16edb0995661da0ed5ef033364", + "_spec": "single-line-log@^1.1.2", + "_where": "/Users/armanshah/Desktop/node-projects/shopping-list/node_modules/nugget", + "author": { + "name": "Tobias Baunbæk", + "email": "[email protected]" + }, + "bugs": { + "url": "https://github.com/freeall/single-line-log/issues" + }, + "bundleDependencies": false, + "dependencies": { + "string-width": "^1.0.1" + }, + "deprecated": false, + "description": "Keep writing to the same line in the terminal. Very useful when you write progress bars, or a status message during longer operations", + "homepage": "https://github.com/freeall/single-line-log#readme", + "keywords": [ + "single", + "line", + "log", + "output", + "overwrite", + "collapse", + "stdout", + "terminal", + "tty", + "cli", + "shell" + ], + "license": "MIT", + "name": "single-line-log", + "repository": { + "type": "git", + "url": "git://github.com/freeall/single-line-log.git" + }, + "scripts": { + "test": "node test.js" + }, + "version": "1.1.2" +} diff --git a/node_modules/single-line-log/test.js b/node_modules/single-line-log/test.js new file mode 100644 index 0000000..c8a2e79 --- /dev/null +++ b/node_modules/single-line-log/test.js @@ -0,0 +1,21 @@ +var 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); |