@kronodeus/nwz
Version:
Browse the top stories from Hacker News right in your terminal.
18 lines • 944 B
JavaScript
import readline from 'node:readline';
import chalk from 'chalk';
import { sleep } from './util.js';
export function printTopTenStories(topTenStories, { url = false } = {}) {
console.log(`\n ${chalk.yellow(`${chalk.underline('HACKER NEWS')} ${chalk.dim('|')} Top 10 ${chalk.dim('|')} ${new Date().toLocaleDateString()}`)}\n\n${topTenStories
.map((story, index) => ` ${chalk.green(`${index}`)}${chalk.dim('.')} ${chalk.bold(story.title)} ${chalk.dim(chalk.italic(`▲ ${story.score}`))}${url ? `\n ${chalk.dim(`➤ ${chalk.italic(story.url)}`)}` : ''}`)
.join('\n')}\n`);
}
export async function printCountdown(seconds, getMessage) {
while (seconds > 0) {
process.stdout.write(getMessage(seconds--));
await sleep(1000);
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
}
console.log(getMessage(seconds--));
}
//# sourceMappingURL=print.js.map