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.


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 thoughts on “Looping busy indicator

Leave a Reply

Your email address will not be published. Required fields are marked *