chalk-animation
chalk-animation copied to clipboard
Support "process.stdout.write" in logging
Hi, i love this project and i wanted to suggest a feature .
i normally use this code to update figures/values on the same line without creating newlines. just like console.log,but it doesn't create a newline always. Example is when creating a countdown/timer in the terminal.
process.stdout.write(`${currentTime}\r`)
and it works perfectly. But when i add it to the chalk-animation syntax like
chalkAnimation.rainbow(process.stdout.write(`${currentTime}\r`));
i get this error
.../node_modules/chalk-animation/index.js:134
text: str.split(/\r\n|\r|\n/),
^
TypeError: str.split is not a function
Is there any way to do this? Thanks
Hi !
You can replace the text of an animation that has already started.
For example, you can add a dot every second like this :
let str = 'Loading...';
const rainbow = chalkAnimation.rainbow(str);
setInterval(() => { rainbow.replace(str += '.'); }, 1000);
(sorry about formatting, I'm on mobile)
hi, i tried doing this
let left = hours + ":" + minutes + ":" + seconds ;
const rainbow = chalkAnimation.rainbow(left);
setInterval(() => { rainbow.replace(left); }, 1000);
but it keep logging on a new line always
and i want the countdown on a single line
I found a solution to this.
I created a pr for it #25
Hi,
There is not need to do a PR that changes the whole thing, just use .replace()
as I told you before !
For example, here is what I can achieve with the following code:
// server.js
import chalkAnimation from 'chalk-animation';
let seconds = 43;
let left = '06:00:' + seconds;
const rainbow = chalkAnimation.rainbow(left);
setInterval(() => {
seconds = seconds - 1;
left = '06:00:' + seconds;
rainbow.replace(left);
}, 1000);
hi, i tried what you suggested and it wasn't working. I waited for hours for a working example but you weren't available. So i had to find a workaround. Thanks for the POC buddy
Yeah sorry I'm usually away from my computer on weekends.
Is the last example working for you?