check out my latest app: Icon Preview
and my latest blog post
Elegant terminal spinner
License: MIT License
check out my latest app: Icon Preview
and my latest blog post
Allow text
to be set by passing it into start
, succeed
, fail
, and stopAndPersist
.
Hi,
I'm using ora spinner in a cli application. This application generates a json as output, when I redirect this output to a file, several characters are placed inside the file beyond my json. See the attached image:
This behavior makes the output not parseable.
Any advice in how to handle this problem completely cleaning the console after calling spinner.stop()?
Thanks!
It would be nice to be able to control what is set to cursorTo in order to support indentation of rows, if desired.
yaodingyd earned $40.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
Living on the CLI with complex task sequences of varying lengths, it would be really useful
to have ora optionally print time on the finish calls.
✔ Create slot SomeText (34s)
Happy to submit a pull request, but wanted to check if there is an appetite for this ?
On the screenshot above, spinner on the left is paused, and you can see the cursor on the right.
But the weird part is that it plays again right before passing to the new symbol (logSymbol.success in my case).
Any idea what can cause this? It's calling a webpack build, so can it be related to the process hanging?
Video: https://files.gitter.im/MoOx/phenomic/dxUG/phenomic.mov
When using ora, other exit related signal handlers fail to run:
// remove the next line, and "cleanup" prints.
require('ora')('Loading unicorns').start().stop();
process.on('SIGINT', function() {
// never called if ora was ever enabled
console.log('cleanup');
});
process.kill(process.pid, 'SIGINT');
This is due to: exit-hook used by restore-cursor not being friendly with other on-exit related strategies.
fails to clear current line when the line length is too long, to be exactly, more than process.stdout.columns. for example, when I set spinner.text = 'abracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebraabracadebra', spinner refuses to clear but moves to the next line, leaving last line dead ...
updated on 12 Mar, 19:01: by viewing the source code, now I know the solution is to break input into lines according to terminal.columns ......
They work fine for me, if I disable the win32 check...
Thanks :-)
I like ora, but I dislike that it defaults to the simple line
spinner if process.platform == 'win32'
since most alternative Windows terminals do support the other more elegant spinners, too.
I have started working on windows terminal detection and have quickly tested which terminals support the default dots
spinner (cmder
, conemu
and mingw
support it; cmd
, powershell
and cygwin
don't).
I know my findings are just exploratory yet and I know it's a niche, but is this something that you would consider to implement in ora? If so, well, I'd like to help out and continue my work. :)
Hi, thank you for the awesome spinner!
I'm setting enabled:false for a specific environment, and I was expecting it also removes any output by spinner.succeed.
Seems like it's not the case.
Is it expected behavior or a bug?
I just started using this awesome package. Thanks for that.
But it seems that it has some issues on windows. Using it in the #0CJS create-guten-block
package.
Here's the issue ahmadawais/create-guten-block#6
TypeError: this.stream.clearLine is not a function
Kindly, take a look.
Which is why on Windows I have to do this
const isWindows = require( 'is-windows' );
const ora = isWindows() ? false : require( 'ora' );
// Init the spinner.
const spinner = ora ? new ora( { text: '', enabled: true } ) : false;
if ( spinner ) {
spinner.start(
`1. Creating the plugin directory called → ${ chalk.black.bgWhite(
` ${ blockName } `
) }`
);
} else {
console.log(
chalk.green( ' 1. Creating the plugin directory called → ' ) +
chalk.black.bgWhite( ` ${ blockName } ` )
);
}
await createPluginDir( blockName );
if ( spinner ) {
spinner.succeed();
}
Which as you can see is less than ideal.
Since the 2.0.0 release is a bump in the major version from the previous version, can you provide some release notes for it? Especially what's breaking and how an user can migrate from 1.4.0
to 2.0.0
.
Thanks.
Hi, (not sure if this is the right place)
I'm using ora, I have it declared like the example in my main node file. I run some things in outside modules. is it possible to update the ora text from within these modules? Perhaps via module.exports
?
what would be the best way of doing this?
Npm version: 3.10.10
Node version: 6.9.4
That's what I get when I npm install
[email protected].
I'm not really sure if that's a problem with this package, I tried to google it but to no avail. I checked my package.json, there is no JSON error plus the file is format using prettier so there would be no format error.
Thanks for that great package. 👍
Hi,
I have a script that tests our REST API running multiple concurrent request. Is it possible to list request line by line with a dedicated spinner at the front of each? In my quick tests, it seems that there can only be one spinner at a time. It seem that creating a second one only updated the text of the first one and so forth.
Thanks
How about starting to return this
from the instance functions so that you can chain it. It would make it easier to create a new spinner and start in the same call.
e.g.
const ora = require('ora')
const spinner = ora('Loading unicorns').start()
setTimeout(() => {
spinner.color = 'yellow'
spinner.text = 'Loading rainbows'
}, 1000)
setTimeout(() => {
spinner.stop()
}, 2000)
const ora = require('ora');
var data = 'start loading...'
ora.promise(
new Promise(function(resolve, reject){
setTimeout(()=>{
console.log(data, 111)
data = 'response not found'
console.log(data, 222)
reject(data);
},3000)
}),
data
);
| start loading...start loading... 111
response not found 222
× start loading...
If the text is too long, every frame is printed on a new line, eventually filling up the screen.
const ora = require('ora');
const spinner = ora('too long! '.repeat(process.stdout.columns));
spinner.start();
// be prepared to hit control-c a bunch of times
Talking about the following gif: https://github.com/sindresorhus/ora/blob/master/screenshot-2.gif
Appreciate the help !
I think it would be nice if we ES2015ified ora
. We could use classes and clean up the code. Supporting node 0.10 and 0.12 for CLI stuff isn't necessary anymore in my opinion.
Latest version available on npm doesn't support .warn()
yet.
I am wondering how I could indent the spinners so that they are not flush with the left side of the terminal? Seems simple enough but it goes over my head.
Hey cool project!
I was using ora and wanted to see the progress of some asynchronous calls but couldn't see a way to adjust the terminal output.
I thought it would be cool if ora
could accept a progress
callback - that will be part of the render.
An example usage would be something like:
'use strict';
const Ora = require('.');
let progress = 0;
const timeoutPromise = timeout =>
new Promise(resolve => {
setTimeout(() => {
resolve();
}, timeout);
}).then(() => {
progress++;
});
const promises = [
timeoutPromise(1000),
timeoutPromise(2000),
timeoutPromise(3000),
timeoutPromise(300),
timeoutPromise(4000)
];
const progressCb = () => {
const percent = Math.round(progress / promises.length * 100);
return `${percent}/100%`;
};
const spinner = new Ora({
progress: progressCb,
text: 'Loading unicorns',
spinner: process.argv[2]
});
spinner.start();
Promise.all(promises).then(() => spinner.succeed());
Right now there's spinner.succeed([text]) and spinner.fail([text]) where the idea is that it's either a success or a failure e.g. due to an error. I'd like a spinner.info([text]), which ends as something like a yellow !.
I want this because it isn't always the case that a function just succeeds or fail, sometimes you can have e.g. a harmless error that when reached you should be made aware of that it's reached but it hasn't succeeded or failed.
So spinner.fail would be for "bad" errors, spinner.info would be for "harmless" errors, and spinner.succeed would be for entirely successful runs.
Thoughts?
I'm using bats to test my cli app moro.
Bats runs end to end tests just like a shell script.
I know in CI and when there's no TTY, ora gets disabled. But I can't figure out why it was working in v1.2.0?
Let me try to create a test case
// utils/spinner.js
const ora = require('ora')
const mainSpinner = ora({
text: '',
spinner: 'flip',
color: 'red'
})
module.exports = mainSpinner
Then somewhere else
const spinner = require('./utils/spinner.js')
spinner.start()
// ... do some stuff
spinner.succeed(`You clocked in successfully`).start()
In version [email protected] this command works by this bats test file:
@test "it says You clocked in" {
run faketime '2020-01-01 08:00:00' moro
assert_success
assert_output_contains 'You clocked in'
}
But in [email protected] it just prints nothing, as spinner.enabled is undefined.
Any ideas would be appreciated :)
arrayOfStuff.map( item => {
spinner.start();
spinner.text = `do stuff to ${item.name}`;
// do stuff that might take a while
})
In an instance like this where you want to make sure the spinner has started, the spinner does not realize it has already started and will start again and again.
If spinner.start()
is called multiple times without a stop
, the extra start
calls are just ignored.
Hi,
I'm running my cli command in docker and the ora fails to start. It seems that there is no function in process.stderr
.
Possible fix is to check the function and return the text per line? (my thought, docker is just streaming the output?).
Thank you for any hints/advices. I can make PR that will check the function.
Martin,
FROM node:8
#... instal etc
# Use the workdir
WORKDIR /usr/src/my-cli
# Install app dependencies
COPY package.json .
COPY package-lock.json .
COPY cli.js .
RUN npm install
RUN npm link
TypeError: this.stream.clearLine is not a function
at Ora.clear (/usr/src/my-cli/node_modules/ora/index.js:53:15)
at Ora.render (/usr/src/my-cli/node_modules/ora/index.js:59:8)
at Ora.start (/usr/src/my-cli/node_modules/ora/index.js:74:8)
at Object.<anonymous> (/usr/src/my-cli/cli.js:42:4)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)
I cannot find anything in the code/documentation about being able to use multiple ora
instances at the same time. This would be very handy when displaying statuses of multiple async operations. For instance, yarn
does something similar with the spinning slashes when adding or updating dependencies.
Many uses of ora
are waiting on a Promise to finish. Would be nice if you somehow could just pass in a Promise have have it handled by ora
. This would be especially nice when #8 is implemented, as it would show a success or failure icon depending on the Promise resolve status.
What should the API look like? It could be a sub-method ora.promise(action)
or an option ora({promise: action})
.
Thoughts? (Anyone)
If I initiate a spinner, console.log
something after initiating it, and then end the spinner, it prints on a new line.
Example:
const ora = require('ora');
const spinner = ora();
spinner.start('initialized spinner');
console.log('\nsomething else');
setTimeout(() => {
spinner.succeed('ended spinner');
}, 3500);
How it ends up: http://i.imgur.com/ok6zSKZ.png
How I want it to end up: http://i.imgur.com/aBeERi0.png
What is the reasoning behind changing the default stream from stdout to stderr?
It took me quite sometime to figure out what broke in my tests. I understand it is a major version change but would be nice if it was in the CHANGELOG/README.
Wouldnt it be better to keep stdout as default as more people are having the same issue? #61
When spawning a command that uses ora
, stream.clearLine
isn't available. This causes ora to throw an exception when it runs this.stream.clearLine();
.
I'm guessing there are other times clearLine
may not be available.
The enable
check could include checking that this.stream.clearLine
is a function, or maybe this.stream.isTTY
is true
.
I think this could be a simple, easy and powerfull solution to #44
People could implement their own elapsed time feature or in my case I want to show the current memory usage on every line.
ex:
import util from 'util';
import colors from 'colors';
import filesize from 'filesize';
const spinner = ora({
text: 'Importing from the database.',
suffix(){
return colors.grey(` (Mem used: ${filesize(util.inspect(process.memoryUsage().rss))})`);
},
prefix: '=> '
}).start();
would print:
⠹ => Importing from the database. (Mem used: 98.2mb)
Barelly add any complexity and it would be pretty versatile.
The following line 22 on the Ora constructor always forces the Line spinner on Windows, even if we choose another spinner:
this.spinner = typeof sp === 'object' ? sp : (process.platform === 'win32' ? cliSpinners.line : (cliSpinners[sp] || cliSpinners.dots)); // eslint-disable-line no-nested-ternary
I accept it the reasoning to force a different default value for windows instead of dots
as usually normal unconfigured CMD or PowerShell are not configured to handle most special characters.
Simply blocking the option to select another spinner is a bit excessive in my opinion, and blocks functionality.
As an example here's VSCode Integrated Terminal with Powershell running the Dots spinner (modified the local Ora code directly):
On the other hand if we changed the code above to something like:
this.spinner = typeof sp === 'object' ? sp : (cliSpinners[sp] || (process.platform === 'win32' ? cliSpinners.line : cliSpinners.dots)); // eslint-disable-line no-nested-ternary
Then by default Windows gets the line
spinner, everybody else gets dots
, but we can still choose another spinner in the options if desired.
Spinner pauses when I start a command using child_process.execSync
.
Is this intended? Did I need to manually render the frames using ora.render()
?
It would be nice to keep a log of finished "texts". Can you please add such option?
So, expected result is, that whenever I change the text previous one is preserved on previous line, shifting output further down. Indicator, obviously, should not be preserved :)
It would be great to get a bool to see if an instance of the spinner is currently spinning.
I read through the code (surprisingly small lib for how much it does!) and it seems like we can functionally read spinner.id
, which will be null if that instance is not spinning and truthy otherwise.
I'm happy to write some logic around this, but since it's not explicitly documented, I wanted to double check that this is a good way to do it and the functionality won't disappear.
thanks!
and here my index.js
'use strict';
const ora = require('ora');
const chalk = require('chalk');
const colors = require('colors');
const mese = require('./month');
const festa = require('./festivity');
// Declaring
var d, day, month, year;
// Asssigning
d = new Date();
today = d.getDate();
year = d.getFullYear();
var status = false;
var spinner = new ora({
text: 'Getting festivities...',
spinner: 'dots',
color: 'yellow'
});
spinner.start();
if ( mese() == festa('epifany').month && today == festa('epifany').day) {
setTimeout(function () {
spinner.text = "📯 It's epifany! 📯";
spinner.succeed();
status = true;
}, 500);
} else {
spinner.text = "Oh no... It's a common day...";
spinner.fail()
}
Thanks in advance.
I want to change the position of the loading symbol,
like below:
$ loading <symbol>
Could I do that?
stroncium earned $30.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
If you use ora
in a subprocess, you can't see the animation (which is perfectly normal, but this is not what this issue is about), but when you take the stdout
of the command, the final state (when you do a spinner.stop()
) doesn't show in it.
I can't tell you how you can fix it, but I have an idea: when you stop the spinner, you make it disappear, and you console.log()
the latest frame. I don't know if it will work).
Hi, awesome spinner 👍, definitely adds alot of spice to those boring cli tools
I'm using through
in my module and it seems to breaking when I introduce ora
into the mix.
The following code should write 123
to number.log
, but it doesn't.
const ora = require('ora');
const fs = require('fs')
const through = require('through')
const rs = through();
rs.push('123');
rs.push(null);
const ws = fs.createWriteStream('number.log', { flags: "a" });
rs.pipe(ws)
const spinner = ora("spin").start();
However, it works if I use a regular PassThrough
stream
var PassThrough = require('stream').PassThrough;
var rs = new PassThrough;
rs.push('123');
rs.push(null);
const ws = fs.createWriteStream('number.log', { flags: "a" });
rs.pipe(ws);
const spinner = ora("spin").start();
Any clue why the incompatibility with through
?
I have implemented log-update
and I love it! Now I want to make it even prettier by adding the spinning dots.
How would I go about using both?
fs.readdirSync('./database/seeds', (err, files) => {
files.forEach((filename) => {
.then(result => {
logUpdate(`${filename}`);
})
})
Flickers really bad in st (every update). Looks great in urxvt.
Can you maybe use [CSI]G
(go to beginning of line) rather than updating entire line? Maybe there is no fix. Still a bug.
Hi,
when doing mycli sub show > stdout.txt
, ora.succeed()
content is not displayed nor it is written to stdout.txt
file. Same if doing mycli sub show | grep .
...While console.log works as exepected.
Here is a gist showing the problem: https://gist.github.com/sulliwane/a2817f02e1bd8f0686098ef04f1c3625
I tried using these options, without success:
{
stream: process.stdout,
enabled: true,
}
note: if using my dockerized CLI, ora output is correctly displayed.
Hey,
first of all, great module! Love it.
I thought that since this module is meant to display progress in something, wouldn't it make sense to also display whether that succeeds or fails?
What I'm imagining is 1) a method .suceed()
that turns the spinner into a green tick, and 2) a method .fail()
that turns the spinner into a red cross (and possibly the text, too?).
What does everyone think about this?
I checked for bouncingBar
and pong
and confirm those are not working.
Open for ideas/help on the best ways to test something like this.
https://github.com/sindresorhus/ora/blob/2a1820f3392339a70292a02875b46027a13d868b/test.js
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.