You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addInteractionListener = addInteractionListener;
exports.confirmAsync = confirmAsync;
exports.pauseInteractions = pauseInteractions;
exports.removeInteractionListener = removeInteractionListener;
exports.resumeInteractions = resumeInteractions;
function _prompts() {
const data = _interopRequireDefault(require("prompts"));
_prompts = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const listeners = [];
/**
* Used to pause/resume interaction observers while prompting (made for TerminalUI).
*
* @param callback
*/
function addInteractionListener(callback) {
listeners.push(callback);
}
function removeInteractionListener(callback) {
const listenerIndex = listeners.findIndex(_callback => _callback === callback);
if (listenerIndex === -1) {
throw new Error('Logger.removeInteractionListener(): cannot remove an unregistered event listener.');
}
listeners.splice(listenerIndex, 1);
}
function pauseInteractions(options = {}) {
for (const listener of listeners) {
listener({
pause: true,
...options
});
}
}
function resumeInteractions(options = {}) {
for (const listener of listeners) {
listener({
pause: false,
...options
});
}
}
async function confirmAsync(options) {
pauseInteractions();
const {
value
} = await (0, _prompts().default)({
type: 'confirm',
name: 'value',
...options
});
resumeInteractions();
return value;
}
//# sourceMappingURL=Prompts.js.map