UNPKG

ggai

Version:

OpenAI LLM Agent Interface

28 lines (25 loc) 634 B
const readline = require('readline'); var rl = null; /** * ask - prompt user at terminal * * @param {String} question the prompt to display * @return {Promise} resolves with answer */ module.exports = ask = (question) => { return new Promise((resolve, reject) => { if (!rl) { rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); } rl.on('SIGINT', reject); if (!question.endsWith(' ')) question += ' '; rl.question(question, answer => { rl.removeListener('SIGINT', reject) resolve(answer); }); }) }