log-update
Advanced tools
Comparing version 1.0.2 to 2.0.0
20
index.js
'use strict'; | ||
var ansiEscapes = require('ansi-escapes'); | ||
var cliCursor = require('cli-cursor'); | ||
const ansiEscapes = require('ansi-escapes'); | ||
const cliCursor = require('cli-cursor'); | ||
const wrapAnsi = require('wrap-ansi'); | ||
function main(stream) { | ||
var prevLineCount = 0; | ||
const main = stream => { | ||
let prevLineCount = 0; | ||
var render = function () { | ||
const render = function () { | ||
cliCursor.hide(); | ||
var out = [].join.call(arguments, ' ') + '\n'; | ||
let out = [].join.call(arguments, ' ') + '\n'; | ||
out = wrapAnsi(out, process.stdout.columns || 80, {wordWrap: false}); | ||
stream.write(ansiEscapes.eraseLines(prevLineCount) + out); | ||
@@ -15,3 +17,3 @@ prevLineCount = out.split('\n').length; | ||
render.clear = function () { | ||
render.clear = () => { | ||
stream.write(ansiEscapes.eraseLines(prevLineCount)); | ||
@@ -21,3 +23,3 @@ prevLineCount = 0; | ||
render.done = function () { | ||
render.done = () => { | ||
prevLineCount = 0; | ||
@@ -28,3 +30,3 @@ cliCursor.show(); | ||
return render; | ||
} | ||
}; | ||
@@ -31,0 +33,0 @@ module.exports = main(process.stdout); |
{ | ||
"name": "log-update", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.", | ||
@@ -13,6 +13,6 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
"test": "xo && node test.js" | ||
}, | ||
@@ -42,8 +42,8 @@ "files": [ | ||
"ansi-escapes": "^1.0.0", | ||
"cli-cursor": "^1.0.2" | ||
"cli-cursor": "^2.0.0", | ||
"wrap-ansi": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
# log-update [![Build Status](https://travis-ci.org/sindresorhus/log-update.svg?branch=master)](https://travis-ci.org/sindresorhus/log-update) | ||
> Log by overwriting the previous output in the terminal. | ||
> Log by overwriting the previous output in the terminal.<br> | ||
> Useful for rendering progress bars, animations, etc. | ||
@@ -19,11 +19,17 @@ | ||
```js | ||
var logUpdate = require('log-update'); | ||
const logUpdate = require('log-update'); | ||
const frames = ['-', '\\', '|', '/']; | ||
let i = 0; | ||
var i = 0; | ||
var frames = ['-', '\\', '|', '/']; | ||
setInterval(() => { | ||
const frame = frames[i = ++i % frames.length]; | ||
setInterval(function () { | ||
var frame = frames[i++ % frames.length]; | ||
logUpdate('\n' + ' ♥♥\n ' + frame + ' unicorns ' + frame + '\n ♥♥'); | ||
}, 100); | ||
logUpdate( | ||
` | ||
♥♥ | ||
${frame} unicorns ${frame} | ||
♥♥ | ||
` | ||
); | ||
}, 80); | ||
``` | ||
@@ -44,3 +50,3 @@ | ||
Persist the logged output. | ||
Persist the logged output.<br> | ||
Useful if you want to start a new log session below the current one. | ||
@@ -62,3 +68,5 @@ | ||
- [speed-test](https://github.com/sindresorhus/speed-test) - Uses this module to render a spinner | ||
- [listr](https://github.com/SamVerschueren/listr) - Uses this module to render an interactive task list | ||
- [ora](https://github.com/sindresorhus/ora) - Uses this module to render awesome spinners | ||
- [speed-test](https://github.com/sindresorhus/speed-test) - Uses this module to render a [spinner](https://github.com/sindresorhus/elegant-spinner) | ||
@@ -68,2 +76,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4225
1
26
74
3
+ Addedwrap-ansi@^2.1.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedcli-cursor@2.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedonetime@2.0.1(transitive)
+ Addedrestore-cursor@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
- Removedcli-cursor@1.0.2(transitive)
- Removedexit-hook@1.1.1(transitive)
- Removedonetime@1.1.0(transitive)
- Removedrestore-cursor@1.0.1(transitive)
Updatedcli-cursor@^2.0.0