Rich output from a Python CLI tool #42
Answered
by
pawamoy
NikosAlexandris
asked this question in
Q&A
-
Unless I miss something, the rich (console markup) print output from a Python (Typer-based) CLI tool is not preserved in the output. For example, cat printsomethingrich.py
and then ``` bash exec="true" result="ansi" source="material-block"
python printsomethingrich.py
``` but the output isn't as expected in the terminal Is there a way to preserve the richness ? |
Beta Was this translation helpful? Give feedback.
Answered by
pawamoy
Apr 8, 2024
Replies: 1 comment 3 replies
-
It's probably because Rich detects its running in a subprocess and therefore deactivates colors. Try forcing them with this: ``` bash exec="true" result="ansi" source="material-block"
export FORCE_COLOR=1 # markdown-exec: hide
python printsomethingrich.py
``` |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
NikosAlexandris
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's probably because Rich detects its running in a subprocess and therefore deactivates colors. Try forcing them with this: