usmanyunusov / nanospinner

🌀 The simplest and tiniest terminal spinner for Node.js
https://npm.im/nanospinner
ISC License
183 stars 15 forks source link

Extend stop method with color option #18

Closed mmustra closed 2 years ago

mmustra commented 2 years ago

Hi @usmanyunusov ,

As "stop" already allows custom mark to be used. I think it would be useful to allow mark's color change as well. For instance If I want to have "!" (warning) mark in different color when I stop the spinner.

Solution Allow "color" property to be used for changing custom's or spinner's mark. No color will be added to custom mark if not passed in options, respecting current behavior. But if you think that custom mark should always use some color, feel free to change logic and tests.

Workarounds ❌ Although you can achieve desired behavior with current API like this:

spinner.update({ text: 'This is a warning', color: 'magenta', frames: Array(10).fill('!') });
spinner.stop();
spinner.update({ color: 'yellow', frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] }); // To revert back spinner color

❌ Or like this, if PR17 goes through:

spinner.update({ text: 'This is a warning', color: 'magenta', frames: ['!'] });
spinner.stop();
spinner.update({ color: 'yellow', frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] }); // To revert back spinner color

✔️ I find this more user friendly:

spinner.stop({ text: 'This is a warning', mark: '!', color: 'magenta' });
usmanyunusov commented 2 years ago

@mmustra Thanks! I'll check in the free time!

usmanyunusov commented 2 years ago

@mmustra Release v.1.0.0