chalk-animation
chalk-animation copied to clipboard
Prevent automatic stop
Im not sure why there is automatic stop on new print into console. Shouldnt it be optional behaviour?
Hi, Sorry about the excessively long delay to reply !
In order to create something which looks like an animation, this module keeps printing then deleting what it just printed.
~~Unfortunately, in a CLI interface, it's only possible to delete the last n
lines, n
being an integer of your choice. So as long as you print something else, the animation cannot work anymore (or it would need to delete what you just printed).~~
I order to keep the animation running after you print something else, this module would need to track everything you print continuously, count the number of printed lines after the animation, and move the cursor to the right line at every frame so the right line is deleted.
I think counting the number of printed lines is a lot more complex than it seems, especially for special cases when lines are deleted after the animation (for example if you run 2 animations at the same time!)
Hope it's clearer, and sorry again!
Hi, Sorry about the excessively long delay to reply !
In order to create something which looks like an animation, this module keeps printing then deleting what it just printed.
~Unfortunately, in a CLI interface, it's only possible to delete the last
n
lines,n
being an integer of your choice. So as long as you print something else, the animation cannot work anymore (or it would need to delete what you just printed).~I order to keep the animation running after you print something else, this module would need to track everything you print continuously, count the number of printed lines after the animation, and move the cursor to the right line at every frame so the right line is deleted.
I think counting the number of printed lines is a lot more complex than it seems, especially for special cases when lines are deleted after the animation (for example if you run 2 animations at the same time!)
Hope it's clearer, and sorry again!
Can we somehow await for one iteration to be done?
I'm not sure I understand your question. Can you please explain what you mean?
I'm not sure I understand your question. Can you please explain what you mean?
For example I've rainbow animation with different text's width, so It takes different time to make one loop from left to right, I want to do something like:
await chalkAnimation.rainbow('Some loooooooooooooooong text');
console.log('Something else');
Sure !
chalkAnimation.rainbow('Some loooooooooooooooong text'); // Start animation
await new Promise(r => setTimeout(r, 1000)); // Wait 1 second
console.log('Something else'); // Stop animation and log something else
For the rainbow animation, one frame lasts 15 ms so you could wait (15 * yourText.length)
to be sure the rainbow goes from the first to the last character
Sure !
chalkAnimation.rainbow('Some loooooooooooooooong text'); // Start animation await new Promise(r => setTimeout(r, 1000)); // Wait 1 second console.log('Something else'); // Stop animation and log something else
For the rainbow animation, one frame lasts 15 ms so you could wait
(15 * yourText.length)
to be sure the rainbow goes from the first to the last character
Thank you!