-
I think it would prove very useful to have an example on how someone could start using rich Console without having to convert all his I suspect that this has something to do with https://github.com/willmcgugan/rich/blob/36efcb5abe9ea8b6a7707243bec89a81e063c01a/rich/progress.py#L476-L509 but is not fully clear to me how this could be achieved as a generic solution, especially as this Apparently the code below seems to be working but is has one serious downside: it uses a private class from rich.console import Console
from rich.progress import _FileProxy
console = Console(record=True)
from rich.progress import _FileProxy
print("foo") # <-- on purpose not using console.print()
assert foo in console.export_text() I wonder if it would be possible to either make If user wants to also to the same for stderr, they would have to create a new console for stderr, something that is already the current way to deal with both streams. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
You could define a print function with the same signature as the builtin print, just like rich.print. Then inject that in to builtins. import builtins
builtin.print = my_print Or you could use the _FileProxy route. Since its private, it would be wise to copy it to your project. |
Beta Was this translation helpful? Give feedback.
-
I think I may have detected an issue with I wrote a small test around this at https://github.com/pycontribs/subprocess-tee/pull/13/checks?check_run_id=1336657368 ConsoleEx is effectively just using the FileProxy approach around sys.stdout/sys.stderr, as seen at https://github.com/pycontribs/subprocess-tee/blob/main/lib/subprocess_tee/rich.py#L58-L59 Sadly what I was looking for was the html export bit... I wonder if I did something wrong or there is a bug in rich. |
Beta Was this translation helpful? Give feedback.
-
In case anyone else is interested about the subject of redirecting stderr/stdout with rich Console, I released https://github.com/pycontribs/enrich which extends Console with this option. |
Beta Was this translation helpful? Give feedback.
In case anyone else is interested about the subject of redirecting stderr/stdout with rich Console, I released https://github.com/pycontribs/enrich which extends Console with this option.