-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
support writing to stderr #177
Comments
If I remember correctly, the bar always uses stdout even if it's redirected. Cf. #171 |
Correct. Yeah, that statement was regarding other progress bars that write to stderr. I've got a branch that writes to stderr by default (main...aerickson:alive-progress:write_to_stderr). |
Hey @aerickson, you're right, perhaps the stderr would be a better default. |
It is interesting that it hasn't been brought up. I guess it's a bit of an obscure feature... most apps with progress bars aren't used as input to other commands (they're end-user UIs)? Awesome. :) Thank you. |
You're welcome. |
Hey @aerickson, it's done!! It was hard work to accomplish it, but the refactoring was worth it. The code: import sys
import time
from alive_progress import alive_bar
def run(f):
with alive_bar(100, file=f) as bar:
for _ in range(100):
time.sleep(.02)
bar()
run(sys.stdout)
run(sys.stderr) Next release man! 👍 |
When will this be released? Thanks! :) |
This does not seem to be working on this branch: https://github.com/aerickson/alive-progress/tree/file_as_argument import time
from alive_progress import alive_bar
def run():
text_object = "foo"
with alive_bar(100, file=text_object) as bar:
for _ in range(100):
time.sleep(0.02)
bar()
# print(text_object)
run() I would expect that when the line Instead of using a string literal as the |
Sorry, I was wrong. I never finished the feature. :( I'm not sure how @rsalmei is doing it in his implementation. |
Hey yeah, I have to try and find time to commit this... It's done for four months now, and still only on my machine. I'll try to get to it next weekend. |
I think that stderr is the preferred destination for progress bars (and errors in command line tools). When the bar is written to stderr, users can still see the progress bar for commands that are redirecting or piping output and can avoid getting the bar in the captured output.
I'm happy to work on this if you can provide some guidance on how you'd like it implemented. As a proof of concept, changing
alive_progress/utils/terminal/tty.py
to sys.stderr had the desired effect.I'm replacing a simple spinner with alive_progress and writing to stderr is one thing that alive_progress is missing.
tqdm writes to stderr by default. See 'file' at https://github.com/tqdm/tqdm#parameters.
The text was updated successfully, but these errors were encountered: