Skip to content

Commit

Permalink
Skip render if the output is unchanged (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
kj800x authored Feb 2, 2020
1 parent 8b3d600 commit a488df3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ const main = (stream, options) => {
}, options);

let prevLineCount = 0;
let prevWidth = getWidth(stream);
let prevOut = '';

const render = (...args) => {
if (!options.showCursor) {
cliCursor.hide();
}

let out = args.join(' ') + '\n';
out = wrapAnsi(out, getWidth(stream), {
const width = getWidth(stream);
if (out === prevOut && prevWidth === width) {
return;
}

prevOut = out;
prevWidth = width;
out = wrapAnsi(out, width, {
trim: false,
hard: true,
wordWrap: false
Expand All @@ -37,10 +46,14 @@ const main = (stream, options) => {

render.clear = () => {
stream.write(ansiEscapes.eraseLines(prevLineCount));
prevOut = '';
prevWidth = getWidth(stream);
prevLineCount = 0;
};

render.done = () => {
prevOut = '';
prevWidth = getWidth(stream);
prevLineCount = 0;

if (!options.showCursor) {
Expand Down

0 comments on commit a488df3

Please sign in to comment.