From d23b0e963a044bef01a21b273eb67284b73fc3e4 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Wed, 5 Aug 2020 18:30:58 -0400
Subject: [PATCH] Create "user confirmation" helper function

---
 src/helper_functions.js | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/helper_functions.js b/src/helper_functions.js
index 4e1b051..77a3d6f 100644
--- a/src/helper_functions.js
+++ b/src/helper_functions.js
@@ -2,6 +2,12 @@
  * Contains misc helper functions.
  */
 
+ // System Imports.
+ const chalk = require('chalk');
+ const readline = require('readline');
+
+ // User Imports.
+
 
 /**
  * Update strings to have an equivalent the "format()" found in Python strings.
@@ -36,4 +42,36 @@ function getCurrentDate() {
 }
 
 
-module.exports = getCurrentDate;
+/**
+ * Pauses current execution to prompt user for yes/no input.
+ * Returns True on yes response, and False on all other responses.
+ *
+ * "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
+    });
+
+    // 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);
+        }
+    }));
+}
+
+
+module.exports = {
+    getCurrentDate,
+    userConfirmation,
+};
-- 
GitLab