console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.43k stars 243 forks source link

is_hidden always returns true when using MultiProgress #341

Closed reynoldsbd closed 2 years ago

reynoldsbd commented 2 years ago

I wrote a custom Log implementation which writes log messages using ProgressBar::println.

As expected, all my log messages got swallowed up when stderr was redirected to a file. Per the docs for ProgressBar::println, this is expected because the draw target is considered hidden (not a TTY).

To work around, I tried to call ProgressBar::is_hidden from within my logger. If the method returns true, I bypass ProgressBar::println and log directly to stderr with eprintln!.

Unfortunately, this technique does not work when using MultiProgress.

I believe the culprit is here:

https://github.com/mitsuhiko/indicatif/blob/92ce4c3f9903dbcb30a087d213ca54d041f462d6/src/draw_target.rs#L125-L131

When self.kind is Remote, we simply return false. Would it make sense to recursively call is_hidden on the remote target instead?

reynoldsbd commented 2 years ago

Side note: I am able to work around by calling console::user_attended_stderr() directly

djc commented 2 years ago

Would it make sense to recursively call is_hidden on the remote target instead?

That certainly sounds sensible, but we'd probably want to audit calls to is_hidden() to make sure the expectations line up.

chris-laplante commented 2 years ago

That certainly sounds sensible, but we'd probably want to audit calls to is_hidden() to make sure the expectations line up.

I submitted a fix for this. There were no calls to is_hidden() to audit, so I think we are in the clear.