From a488df3f4c1267e8aef52e4ea7dc1545ba60ab9d Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Sun, 2 Feb 2020 09:02:30 -0500 Subject: [PATCH] Skip render if the output is unchanged (#45) --- index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2c9bca4..5936db1 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,8 @@ const main = (stream, options) => { }, options); let prevLineCount = 0; + let prevWidth = getWidth(stream); + let prevOut = ''; const render = (...args) => { if (!options.showCursor) { @@ -26,7 +28,14 @@ const main = (stream, options) => { } 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 @@ -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) {