Franklin

Looping busy indicator

Let’s just stash this here…

Javascript code snippet for node.js to display a looping busy indicator on the console output.

ezgif.com-gif-maker

What it does

First define the characters for the loop: |/―\\. Can be any ASCII character you like.

Next iterate the characters, wait ms time before each character and reset the index to 0 at the end of the chars.

Then write the string to the console. When you use console.log each change is written on a new line, because that appends \n to the output. With process.stdout.write you can use \r to reset the cursor to the beginning of the line and then overwrite the displayed characters. The space at the end is there only for good looks.

Related stuff

2 Comments

  1. I am impressed!!! Gonna use for my node based youtube video downloader project

Leave a Reply