cli-prompts
Version:
Tiny module for creating beautiful CLI prompts
74 lines (65 loc) • 2.8 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var events = require('events');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
class Prompt extends events.EventEmitter {
constructor(options) {
super();
this.options = options;
this.state = {
skipped: false
};
}
run() {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
this.once('submit', resolve);
this.once('cancel', reject);
if (yield this.skip()) {
this.render = () => { };
return this.submit();
}
yield this.initialize();
this.emit('run');
}));
}
skip() {
return __awaiter(this, void 0, void 0, function* () {
this.state.skipped = this.options.skip === true;
if (typeof this.options.skip === 'function') {
this.state.skipped = yield this.options.skip.call(this);
}
return this.state.skipped;
});
}
initialize() {
return __awaiter(this, void 0, void 0, function* () {
});
}
submit() {
return __awaiter(this, void 0, void 0, function* () {
});
}
render() {
throw new Error(`Expect prompt to have custom render method`);
}
}
exports.Prompt = Prompt;
;