From 6ef65fb26aae4716781d92f476954bbcfc4f16e1 Mon Sep 17 00:00:00 2001 From: mrfry Date: Wed, 28 Apr 2021 17:36:52 +0200 Subject: [PATCH] rmDuplicates not dying when its output is piped --- src/standaloneUtils/rmDuplicates.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/standaloneUtils/rmDuplicates.js b/src/standaloneUtils/rmDuplicates.js index 105941d..5a5c446 100644 --- a/src/standaloneUtils/rmDuplicates.js +++ b/src/standaloneUtils/rmDuplicates.js @@ -121,12 +121,9 @@ function removePossibleAnswersDuplicates(path) { count++ }) + let removed = 0 dirs.forEach((currDir) => { const contents = fs.readdirSync(path + '/' + currDir) - let removed = 0 - log( - `Processing ${C('green')}${currDir}${C()} (${contents.length} files) ...` - ) contents.forEach((currFile) => { const currPath = path + '/' + currDir + '/' + currFile @@ -173,10 +170,8 @@ function removePossibleAnswersDuplicates(path) { }) }) }) - - log(`Removed ${C('red')}${removed}${C()} files`) - hr() }) + log(`Removed ${C('red')}${removed}${C()} files total`) log(`${C('green')}Deleting empty directories ...${C()}`) count = dirs.length @@ -415,14 +410,19 @@ function hr() { } function log(text) { - process.stdout.clearLine() - process.stdout.cursorTo(0) + utils.AppendToFile(text, globalLog) + if (process.stdout.isTTY) { + process.stdout.clearLine() + process.stdout.cursorTo(0) + } console.log(text) - utils.AppendToFile(text, globalLog) } function writeInSameLine(text, returnToLineStart) { + if (!process.stdout.isTTY) { + return + } process.stdout.clearLine() process.stdout.cursorTo(0) process.stdout.write(text) @@ -434,6 +434,9 @@ function writeInSameLine(text, returnToLineStart) { } function printProgressBar(current, total) { + if (!process.stdout.isTTY) { + return + } const width = process.stdout.columns - 30 if (width <= 0) {