Skip to content

Commit

Permalink
close prompt on error
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 10, 2023
1 parent aff451e commit e151036
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class TerminalAdapter {
return string.split('\n').map(line => this[`_colorDiff${name}`](line)).join('\n');
}

close() {
if (this.promptUi) {
this.promptUi.close();
}
}

/**
* Prompt a user for one or more questions and pass
* the answer(s) to the provided callback.
Expand All @@ -51,16 +57,14 @@ class TerminalAdapter {
* @param {Function} [cb] Deprecated: callback for backward compatibility.
* @return {Object} promise answers
*/
prompt(questions, answers, cb) {
if (typeof answers === 'function') {
cb = answers;
answers = undefined;
}
const promise = this.promptModule(questions, answers);
if (typeof cb === 'function') {
promise.then(answers => cb(answers));
}
return promise;
prompt(questions, answers, cb = () => {}) {
const promptPromise = this.promptModule(questions, typeof answers === 'function' ? undefined : answers);
this.promptUi = promptPromise.ui;
promptPromise.then(result => {
delete this.promptUi;
(typeof answers === 'function' ? answers : cb)(result);
});
return promptPromise;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ class Environment extends Base {

this.runLoop.on('error', error => {
this.emit('error', error);
this.adapter.close();
});

this.runLoop.on('paused', () => {
Expand Down

0 comments on commit e151036

Please sign in to comment.