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

ability so force progress reporting even when output stream is not a TTY #110

Open
lbeschastny opened this issue Sep 12, 2015 · 5 comments

Comments

@lbeschastny
Copy link

node-progress TTY detection as an awesome feature, but sometimes terminal connection is lost due to stdio piping.

Here is a very simple example:

node ./simple.js 2>&1 | cat

There is no way to check in simple.js that the end of srderr pipe is connected to some terminal, we only know that srderr stream is piped somewhere. But as a user I know it'll end up in a terminal and still want to see a progress bar.

@lbeschastny
Copy link
Author

Found the following workaround:

var tty = require('tty').WriteStream.prototype;
Object.getOwnPropertyNames(tty).forEach(function (key) {
  process.stderr[key] = tty[key];
})
process.stderr.columns = 80; // almost all terminals have at least 80 columns

@lbeschastny
Copy link
Author

This should also help with #104

@nicojs
Copy link

nicojs commented Jan 2, 2017

@lbeschastny wouldn't your solution fail in some use cases when the stream does not support stream.clearLine, stream.cursorTo, etc? Or simply not clear the line? For example when using jenkins, travis setups, etc.

In that case i want to suggest a different solution: fall back to a simple write-only progress bar. The bar would simply redraw on a new line. The time between redraws (refresh rate) would be configurable, with a default to 10 seconds intervals.

I could create a PR for this (i'm creating a similar solution for stryker-mutator/stryker-js#212)

@lbeschastny
Copy link
Author

lbeschastny commented Jan 13, 2017

@nicojs it's not a real solution, but rather a simple workaround. And it definitely won't work for non-tty clients like jenkins.

It would be really nice to have some good failover for non-tty clients like a simple write-only progress bar.

Though drawing a new bar every n seconds doesn't look like a good idea here because some processes may take quite a while to complete.

The best solution is to use a simple incremental bar (when you just add a new symbol to an existing line from time to time), but it would conflict with current rich progress bar templating mechanics.

Another possible solution is to draw a new bar after every n percents and thus guarantee that resulting output will be small.

ryan-frankel pushed a commit to ryan-frankel/node-progress that referenced this issue Dec 8, 2017
…eTTY that will force TTY so that the progress bar can be used with tee and or redirected to an output file.
@ryan-frankel
Copy link

I made a PR that includes this fix as an option: #168

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

3 participants