diff --git a/index.js b/index.js index 093b190..dbbd4a4 100755 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ const packageInfo = require('./package.json'); const path = require('path'); const paths = require('xdg-app-paths')(packageInfo.name); const progress = require('cli-progress'); +const readline = require('readline'); const request = require('request'); const sanitizeFilename = require('sanitize-filename'); const url = require('url'); @@ -41,6 +42,15 @@ const ALLOWED_TYPES = SUPPORTED_PLATFORMS.concat(['all']).sort(); const ALLOWED_SORT_PROPERTIES = ['date', 'name'].sort(); +// work-around for "hang" after 'enquirer' /cancel() on windows platforms; see +// * arises from "node" bug after Node-v10.2 thru Node-v14.6 => see +// ToDO: keep apprised of any fix for this via `enquirer` +const readlineOldClose = readline.Interface.prototype.close; +readline.Interface.prototype.close = function () { + this.terminal = false; + readlineOldClose.call(this); +}; + commander .version(packageInfo.version) .option( @@ -469,7 +479,7 @@ function displayOrders(next, orders) { process.stdout.write('\x1Bc'); // Clear console - let prompt = new enquirer.MultiSelect({ + const prompt = new enquirer.MultiSelect({ name: 'bundle', message: 'Select bundles to download', choices: options, @@ -495,19 +505,18 @@ function displayOrders(next, orders) { } return this.render(); }, - }) + }); + + prompt .run() + .catch(() => {}) // empty selections throw an `alert()` (with no information) => so, ignore all errors .then((answers = []) => { // console.log(answers); - next( - null, - orders.filter((item) => { - return answers.indexOf(item.product.human_name) !== -1; - }) - ); - }) - .catch(() => { - next(null, []); + const o = orders.filter((item) => { + return answers.indexOf(item.product.human_name) !== -1; + }); + // console.log(o); + next(null, o); }); } diff --git a/package-lock.json b/package-lock.json index 846d284..ae7ecd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3612,6 +3612,11 @@ "string_decoder": "~0.10.x" } }, + "readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=" + }, "rechoir": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", diff --git a/package.json b/package.json index 4ba0d79..d195161 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "make-dir": "^3.0.2", "nasa-keypath": "0.0.1", "nightmare": "^3.0.2", + "readline": "^1.3.0", "request": "^2.88.2", "sanitize-filename": "^1.6.3", "xdg-app-paths": "^5.3.0"