Let’s just stash this here…
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.