Ora

Ora (GitHub: sindresorhus/ora, License: MIT, npm: ora)

When you are making command line tools using Node.js you are probably using something like Vorpal or commander. When you want to communicate to the user that she needs to wait there are multiple things you could do. You could show a progress bar, but for that you would need to know when to fill it and when its done. Maybe you do not have this and do not wanna be bothered with implementing this. Well the maybe you wanna show a loading spinner like this:


Well then Ora is the spinner for you. It works very straight forward:

const ora = require('ora');
const mySpinner = ora('Loading undead unicorns');
mySpinner.start();

// Update
setTimeout(() => {
 spinner.color = 'yellow';
 spinner.text = 'Killing all the undead unicorns';
}, 1000);

One of the great things about this spinner is that it will not clutter up your CI logs with stuff like:

|
\
-
/
-
|

or

[= ]
[== ]
[=== ]
[====]

Since it will gracefully not do anything when there’s no TTY. When you do not like the default spinner, you could select another one from the list of spinners or create your own like so:

const mySpinner{
 interval: 80,
 frames: ['-', '+', '-']
};
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容