Closed Yomguithereal closed 1 year ago
Another solution would also be to add some kwarg letting users indicate how many cols they want because they might know better.
Hello @Yomguithereal! Sorry for the delay. Thanks, man! That's really a bug, I've never thought about grabbing the terminal size with a different handle. I'll fix it as soon as I can.
Hey @Yomguithereal, it is ready! The PR is #231, I'm glad I could find some time to work on this.
Released 👍
Thanks @rsalmei
Hello @rsalmei, thanks for your awesome library.
I have a little issue when printing the progress bar using
file=sys.stderr
and piping the stdout of a script into a file. Here is a script reproducing the problem (note that the terminal has to be ~130 cols wide for it to show):If you run:
everything works fine. But if you run:
then the progress bar will be erroneously truncated.
This happens because
alive_progress
always uses stdout cols to print itself, and when piped to a file,shutil.get_terminal_size
always return some default desirable value (usually around 80). Related code can be found here.Now if I monkey-patch your library using the following code:
it fixes the problem.
Of course my code is naive and should be a little bit more subtle, especially when dealing with files that do not have a
fileno
etc. and I don't know if this kind of solution would break something else. But if you feel this is a good fix, I can submit a PR.I wish you a good evening