log-update
Advanced tools
Comparing version 3.3.0 to 3.4.0
29
index.js
@@ -21,3 +21,5 @@ 'use strict'; | ||
let prevLineCount = 0; | ||
let previousLineCount = 0; | ||
let previousWidth = getWidth(stream); | ||
let previousOutput = ''; | ||
@@ -29,4 +31,11 @@ const render = (...args) => { | ||
let out = args.join(' ') + '\n'; | ||
out = wrapAnsi(out, getWidth(stream), { | ||
let output = args.join(' ') + '\n'; | ||
const width = getWidth(stream); | ||
if (output === previousOutput && previousWidth === width) { | ||
return; | ||
} | ||
previousOutput = output; | ||
previousWidth = width; | ||
output = wrapAnsi(output, width, { | ||
trim: false, | ||
@@ -36,13 +45,17 @@ hard: true, | ||
}); | ||
stream.write(ansiEscapes.eraseLines(prevLineCount) + out); | ||
prevLineCount = out.split('\n').length; | ||
stream.write(ansiEscapes.eraseLines(previousLineCount) + output); | ||
previousLineCount = output.split('\n').length; | ||
}; | ||
render.clear = () => { | ||
stream.write(ansiEscapes.eraseLines(prevLineCount)); | ||
prevLineCount = 0; | ||
stream.write(ansiEscapes.eraseLines(previousLineCount)); | ||
previousOutput = ''; | ||
previousWidth = getWidth(stream); | ||
previousLineCount = 0; | ||
}; | ||
render.done = () => { | ||
prevLineCount = 0; | ||
previousOutput = ''; | ||
previousWidth = getWidth(stream); | ||
previousLineCount = 0; | ||
@@ -49,0 +62,0 @@ if (!options.showCursor) { |
{ | ||
"name": "log-update", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.", | ||
"license": "MIT", | ||
"repository": "sindresorhus/log-update", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
@@ -8,0 +9,0 @@ "name": "Sindre Sorhus", |
@@ -8,3 +8,2 @@ # log-update [![Build Status](https://travis-ci.org/sindresorhus/log-update.svg?branch=master)](https://travis-ci.org/sindresorhus/log-update) | ||
## Install | ||
@@ -16,3 +15,2 @@ | ||
## Usage | ||
@@ -39,3 +37,2 @@ | ||
## API | ||
@@ -63,3 +60,3 @@ | ||
### logUpdate.create(stream, [options]) | ||
### logUpdate.create(stream, options?) | ||
@@ -70,7 +67,7 @@ Get a `logUpdate` method that logs to the specified stream. | ||
Type: `Object` | ||
Type: `object` | ||
##### showCursor | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -89,3 +86,2 @@ | ||
## Examples | ||
@@ -97,5 +93,12 @@ | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-log-update?utm_source=npm-log-update&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
7320
124
98