Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Created August 14, 2018 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonschlinkert/74127a43731b49fb541462820bda1b44 to your computer and use it in GitHub Desktop.
Save jonschlinkert/74127a43731b49fb541462820bda1b44 to your computer and use it in GitHub Desktop.
const countdown = (msgFn, fn, count = 3, interval = 500) => {
let timer = setInterval(() => {
process.stdout.write('\u001b[?25l');
process.stdout.write('\u001b[2K\r');
process.stdout.write(msgFn(count));
if (count-- === 0) {
process.stdout.write('\u001b[?25h');
process.stdout.write('\u001b[2K\r');
clearInterval(timer);
fn();
}
}, interval);
};
countdown(n => `Starting example in ${n}`, () => console.log('Lift off!'), 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment