rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

Unable to redirect alive-progress output #171

Closed scott-parkhill closed 2 years ago

scott-parkhill commented 2 years ago

First of all, I want to say thank you for making such an amazing program. I love it, and you can tell that this was made with love, too. It really shows, and I think you've done an amazing job, and you also have amazing documentation. This is so easy to use and absolutely stellar.

The one thing I am struggling with though is redirecting the progress bar to the GUI I made. I've redirected stdout and stderr to GUI, but the progress bar still displays only within the terminal, and I've been unable to find a way around this. Do you have any suggestions for me, please? Is this even possible?

TheTechRobo commented 2 years ago

Don't do that - your GUI probably won't recognise the control characters even if you do figure out how to redirect it.

Best way: Make a GUI-native progress bar, and add a raw progress option so you know the processed/total numbers. (That's assuming you can't just get the progress details through the GUI; if you can, that would be easiest.)

Second-best way: Embed a terminal (e.g. xterm on Unix) into the window and run the progress bar there. Works on both Tkinter and PyGObject; haven't tried any others.

scott-parkhill commented 2 years ago

Awesome, great to know, thank you very much @TheTechRobo. I appreciate your reply and suggestions!

rsalmei commented 2 years ago

First of all, I want to say thank you for making such an amazing program. I love it, and you can tell that this was made with love, too. It really shows, and I think you've done an amazing job, and you also have amazing documentation. This is so easy to use and absolutely stellar.

Thank you, man! I really appreciate your words!

Thank you also @TheTechRobo for the answer! @scott-parkhill He is right, I don't think you could easily make a pass-through so as to keep alive-progress working, given the several ANSI Escape Codes I use.

But to give you a hint, I do not use internally sys.__stdout__ anymore, which is the raw terminal. This means that, whenever you start an alive-progress context, it will always use the current stdout, regardless of any redirection you might have made... I use this to support pytest for instance, which needs to redirect and capture the stdout.

See ya 👋