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

Ora swallows stdout just before .stop() #90

Open
shaunwarman opened this issue Dec 12, 2018 · 11 comments
Open

Ora swallows stdout just before .stop() #90

shaunwarman opened this issue Dec 12, 2018 · 11 comments
Labels
bug 💵 Funded on Issuehunt This issue has been funded on Issuehunt

Comments

@shaunwarman
Copy link

shaunwarman commented Dec 12, 2018

Issuehunt badges

It looks as though ora swallows any stdout happening just before the .stop().

Example

const ora = require('ora');

const spinner = ora({
  text: 'spinning...\n',
  color: 'yellow'
});

spinner.start();

setTimeout(() => {
  console.log('STOP');
  spinner.stop();
}, 1000);

There is a $30.00 open bounty on this issue. Add more on Issuehunt.

@shaunwarman shaunwarman changed the title Ora swallows stdout just before spinner.stop() Ora swallows stdout just before .stop() Dec 12, 2018
@jamisonl
Copy link

I just experienced the same issue. I resolved it by removing the linebreak at the end of text. Try removing this and see if that works as a temporary fix.

@shaunwarman
Copy link
Author

Actually, re-opening as it's swallowing my debug logging. If ora is still spinning, it just eats any stdout / stderr until stopped.

@IssueHuntBot
Copy link

@IssueHunt has funded $30.00 to this issue.


@stroncium
Copy link
Contributor

stroncium commented Apr 2, 2019

ora doesn't handle output to the same stream well while spinner is running, be it before stop or right after start. The only way to mitigate this I see is to masquerade underlying stream while we have something displayed in it to clear spinner - output data - output spinner again. But do we want to perform such invasive operations for this small cause?
Also, it's generally a issue with most applications in all languages running in similar modes.

//NOTE #97 is related

@stroncium
Copy link
Contributor

Also, theoretically, implementing this with minor additions would allow adding multiple spinners. But I still don't think that is worth the trouble. Should we maybe provide a method on spinner to print some text above it instead? It's simpler and doesn't require changing stream. (Plus, even if we do change stream, we can handle just writing to it, but handling all the tty-specific methods is more complex than everything the lib does so far.)

// @sindresorhus

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 10, 2019
@sindresorhus
Copy link
Owner

It would be nice to support normal console.log's. I've had to work around this problem several times before. For example: https://github.com/sindresorhus/npm-name-cli/blob/5ee06c56ea6c0e1249efae03d41c067bdd4444a5/cli.js#L79-L81

@sindresorhus
Copy link
Owner

ora doesn't handle output to the same stream well while spinner is running, be it before stop or right after start.

But if the console.log statements are executed in the same tick as spinner.stop(), then Ora could take that into account. We would have to hook the stream write method though to be able to count lines, something similar to https://github.com/ivanseidel/node-draftlog/blob/master/lib/LineCountStream.js

@ngocdaothanh
Copy link

You can override console.log before spinning, then restore it later.

Because when you override, you have control of console.log, you can do whatever you want.

Example:

const ora = require('ora');

const consoleLog = console.log;
console.log = (text) => {
  spinner.text += '\n' + text;
};

const spinner = ora({
  text: 'spinning...',
  color: 'yellow'
});

spinner.start();

setTimeout(() => {
  console.log('STOP');
  spinner.succeed(spinner.text);

  console.log = consoleLog;
  console.log('It works');
}, 1000);

Output:

✔ spinning...
STOP
It works

@stroncium
Copy link
Contributor

stroncium commented Sep 14, 2019

@ngocdaothanh console.log isn't the only thing to write to stdout, but even with console.log only things get much more complicated once there are escape sequences and multilines in play.

@ngocdaothanh
Copy link

Yeah when there are too many lines, there's this problem:
#121

@Saif-Shines
Copy link

I have a significant problem with this when I have to write test cases for my CLI commands. I can't write tests for stdout because they're gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 💵 Funded on Issuehunt This issue has been funded on Issuehunt
Projects
None yet
Development

No branches or pull requests

7 participants