Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to use ora when logging things after the first initiation of a spinner? #49

Open
aetheryx opened this issue Jul 31, 2017 · 6 comments

Comments

@aetheryx
Copy link

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

@prodrammer
Copy link

I took the approach of logging out to a file instead. In my case, I'm running shell commands:

some_command_here >> some.log 2>&1

The basic flow is:

  • Start the spinner
  • Run the command
  • On failure, call spinner.fail({fail_text})
  • On success, call spinner.succeed({success_text})

I find this a good alternative to what is proposed, and the user experience is better. For example, what happens when you 'interrupt' so much that the spinner runs off the screen?

@aetheryx
Copy link
Author

I could understand that. As an alternative, I found I could do what I wanted to achieve with draftlog. I just re-made ora's functionality in draftlog, ending up in something like this.
A single spinner is understandable though. For instance, draftlog completely breaks when outputting the logs to a file - so usage with pm2 etc is out of the question. I believe ora on the other hand deals with pm2 / files fine.

@novemberborn
Copy link
Contributor

Ora always clears the last line in the TTY stream. It assumes it was the last to write to the stream, so if you write some lines yourself then you break that assumption.

What you could do if you can control when you write to the stream is to call .clear() and then write the result of calling.frame(). .render() currently doesn't work because it clears again, removing your previous output.

@ghost
Copy link

ghost commented Feb 28, 2018

well, this isn't a perfect solution, but you can use this as a starting point to build a function that could handle it better. I cooked this up in like 5 mins.

let buffer;

function logtext(text) {
    buffer = text;
    spinner.text = `${spinner.text}\n${text}`
}

spinner.start('initialized spinner');

logtext('something else');

setTimeout(() => {
    spinner.succeed(`ended spinner\n${buffer}`);
    process.exit();
}, 3500);

@mhemrg
Copy link

mhemrg commented Jun 7, 2018

As @novemberborn said, this works:

const logInfo = (text) => {
  spinner.clear();
  spinner.frame();
  console.log(text);
}

Luiserebii added a commit to Luiserebii/solidity-deploy that referenced this issue May 2, 2019
…. Not really the best... uncertain how to fully implement this well, but this was very valuable in my guessing: sindresorhus/ora#49 (comment)
@ngocdaothanh
Copy link

You can override console.log, as in the example mentioned at #90.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants