UNPKG

build-in-public-bot

Version:

AI-powered CLI bot for automating build-in-public tweets with code screenshots

69 lines 2.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prompt = prompt; exports.confirm = confirm; exports.select = select; const readline_1 = __importDefault(require("readline")); const chalk_1 = __importDefault(require("chalk")); async function prompt(message, options = {}) { const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout }); return new Promise((resolve) => { const displayMessage = options.default ? `${message} ${chalk_1.default.gray(`(${options.default})`)}: ` : `${message}: `; rl.question(displayMessage, (answer) => { rl.close(); const value = answer.trim() || options.default || ''; if (options.validate) { const validation = options.validate(value); if (validation !== true) { console.log(chalk_1.default.red(validation || 'Invalid input')); resolve(prompt(message, options)); return; } } resolve(value); }); if (options.mask) { rl._writeToOutput = function _writeToOutput(stringToWrite) { if (stringToWrite.includes(displayMessage)) { rl.output.write(stringToWrite); } else { rl.output.write('*'); } }; } }); } async function confirm(message, defaultValue = false) { const defaultHint = defaultValue ? 'Y/n' : 'y/N'; const answer = await prompt(`${message} ${chalk_1.default.gray(`(${defaultHint})`)}`, { default: defaultValue ? 'y' : 'n' }); return answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes'; } async function select(message, choices) { console.log(`\n${message}`); choices.forEach((choice, index) => { console.log(` ${chalk_1.default.cyan(`${index + 1})`)} ${choice.label}`); }); console.log(); const answer = await prompt('Select an option', { validate: (input) => { const num = parseInt(input, 10); if (isNaN(num) || num < 1 || num > choices.length) { return `Please enter a number between 1 and ${choices.length}`; } return true; } }); return choices[parseInt(answer, 10) - 1].value; } //# sourceMappingURL=prompts.js.map