@kronodeus/nwz
Version:
Browse the top stories from Hacker News right in your terminal.
26 lines • 807 B
JavaScript
import chalk from 'chalk';
export async function promptForStorySelection(stories, cb) {
while (true) {
const userInput = (await prompt(` If you'd like to read more, make a selection ${chalk.green('(0-9)')}: `))?.trim() ||
'exit';
const index = parseInt(userInput);
if (stories[index]) {
await cb(stories[index]);
}
else if (userInput === 'exit') {
return;
}
else {
console.log(chalk.red(` Invalid input: ${userInput}\n`));
}
}
}
async function prompt(message) {
process.stdout.write(message);
return new Promise((resolve) => {
process.stdin.once('data', (data) => {
resolve(data.toString().trim());
});
});
}
//# sourceMappingURL=prompt.js.map