diff --git a/package.json b/package.json index c7af6d54c3adfea4261358d46a67ceea72762328..f70d9e73bd209f63540648a36a732961dc155112 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "chalk": "^4.1.0", - "mysql2": "^2.1.0" + "mysql2": "^2.1.0", + "readline-sync": "^1.4.10" } } diff --git a/src/helper_functions.js b/src/helper_functions.js index 77a3d6f7f9a706a5de3eb5629ac4fe72b1343df5..efa0fbcc0b637012fee65a22ffbd3ff7f44200eb 100644 --- a/src/helper_functions.js +++ b/src/helper_functions.js @@ -4,7 +4,7 @@ // System Imports. const chalk = require('chalk'); - const readline = require('readline'); + const readline = require('readline-sync'); // User Imports. @@ -48,26 +48,26 @@ function getCurrentDate() { * * "Readline" logic from https://stackoverflow.com/a/50890409 */ -async function userConfirmation() { - // Create "readline" instance to get user input. - const read = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); +function userConfirmation() { // Get user input. - return new Promise(resolve => read.question(' Is this okay? ' + chalk.blue('[ Yes | No ]\n'), (user_input) => { - // Close "readline" instance to save processing power. - read.close(); - - // Handle based on user response. - user_input = user_input.toLowerCase(); - if (user_input == 'yes' || user_input == 'ye' || user_input == 'y') { - resolve(true); - } else { - resolve(false); + try { + var user_input = readline.question('Is this okay? {}\n'.format(chalk.blue('[ Yes | No ]'))); + } catch (err) { + // Ignore "timeout" error. Display all others. + if (err.code != 'ETIMEDOUT') { + console.log(err); + throw err; } - })); + } + + // Handle based on user response. + user_input = user_input.toLowerCase(); + if (user_input == 'yes' || user_input == 'ye' || user_input == 'y') { + return true; + } else { + return false; + } }