-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Write output to stderr instead of stdout #1
Conversation
Ah right, the other libs do this too. Let me do some quick tests. |
Hmm, I bet it's some kind of buffering issue. |
In both |
I seem to have fixed this issue, commit coming shortly... |
Wrapping One issue I noticed while testing is that
then the output will be screwed up even though stderr is a perfectly good terminal. I don't see how to fix that downstream, though. |
Indeed that fixes it. I had assumed that someone would mention |
This is more appropriate for dynamic output that's not intended to be machine-readable. `std::io::Stderr` is unbuffered by default, so add explicit line-buffering to prevent the terminal cursor from jumping around. Also update the examples to write their messages to stderr as well, for consistency.
"{:<l$} [{:->f$}] 0%", | ||
label, | ||
"", | ||
l = twidth - w - 8 - 5, | ||
f = w | ||
); | ||
self.out.flush().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flush
was removed here, but kept elsewhere. What was the intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we call writeln!
and self.out
is line-buffered it'll flush anyway. The other cases don't write a newline so an explicit flush is needed.
@@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex}; | |||
use std::time::Duration; | |||
|
|||
fn main() { | |||
println!("Starting bars..."); | |||
eprintln!("Starting bars..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can stay as println!
, they're just demos after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to keep them that way? eprintln
seems more consistent to me, but I'll defer to your judgement.
Thanks for this! Releasing a new version right away. |
stderr is appropriate for dynamic output that's not intended to be machine-readable.
Even better on POSIX systems would be writing to
/dev/tty
, but I'm not sure what the cross-platform equivalent is there.