aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
commit6c8128f9fd5a5d0be115806c35a21b3d683df8d6 (patch)
treef46c2f6b3b9b294ff32bd75c08ccdc9e7a8cc4ef /sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js
parent2400b84e95913665da6279114168148444b8f9ab (diff)
parent7d3640f824f46490b47bd95f1c5a16644f712068 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into logo
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js')
-rw-r--r--sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js
new file mode 100644
index 00000000..547e5658
--- /dev/null
+++ b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/ui/baseUI.js
@@ -0,0 +1,99 @@
+'use strict';
+const _ = {
+ extend: require('lodash/extend'),
+ omit: require('lodash/omit'),
+};
+const MuteStream = require('mute-stream');
+const readline = require('readline');
+
+/**
+ * Base interface class other can inherits from
+ */
+
+class UI {
+ constructor(opt) {
+ // Instantiate the Readline interface
+ // @Note: Don't reassign if already present (allow test to override the Stream)
+ if (!this.rl) {
+ this.rl = readline.createInterface(setupReadlineOptions(opt));
+ }
+
+ this.rl.resume();
+
+ this.onForceClose = this.onForceClose.bind(this);
+
+ // Make sure new prompt start on a newline when closing
+ process.on('exit', this.onForceClose);
+
+ // Terminate process on SIGINT (which will call process.on('exit') in return)
+ this.rl.on('SIGINT', this.onForceClose);
+ }
+
+ /**
+ * Handle the ^C exit
+ * @return {null}
+ */
+
+ onForceClose() {
+ this.close();
+ process.kill(process.pid, 'SIGINT');
+ console.log('');
+ }
+
+ /**
+ * Close the interface and cleanup listeners
+ */
+
+ close() {
+ // Remove events listeners
+ this.rl.removeListener('SIGINT', this.onForceClose);
+ process.removeListener('exit', this.onForceClose);
+
+ this.rl.output.unmute();
+
+ if (this.activePrompt && typeof this.activePrompt.close === 'function') {
+ this.activePrompt.close();
+ }
+
+ // Close the readline
+ this.rl.output.end();
+ this.rl.pause();
+ this.rl.close();
+ }
+}
+
+function setupReadlineOptions(opt) {
+ opt = opt || {};
+ // Inquirer 8.x:
+ // opt.skipTTYChecks = opt.skipTTYChecks === undefined ? opt.input !== undefined : opt.skipTTYChecks;
+ opt.skipTTYChecks = opt.skipTTYChecks === undefined ? true : opt.skipTTYChecks;
+
+ // Default `input` to stdin
+ const input = opt.input || process.stdin;
+
+ // Check if prompt is being called in TTY environment
+ // If it isn't return a failed promise
+ if (!opt.skipTTYChecks && !input.isTTY) {
+ const nonTtyError = new Error(
+ 'Prompts can not be meaningfully rendered in non-TTY environments'
+ );
+ nonTtyError.isTtyError = true;
+ throw nonTtyError;
+ }
+
+ // Add mute capabilities to the output
+ const ms = new MuteStream();
+ ms.pipe(opt.output || process.stdout);
+ const output = ms;
+
+ return _.extend(
+ {
+ terminal: true,
+ input,
+ output,
+ },
+ _.omit(opt, ['input', 'output'])
+ );
+}
+
+module.exports = UI;