Add rich colors to print_msg#5125
Conversation
Not sure what the best approach would be to update the tests accordingly... Maybe force disable Rich by setting some environment variable or configuring with |
|
Yeah i think running all current tests with |
9975190 to
f5f9a63
Compare
print_msgprint_msg
|
de4f102 Should avoid breaking stuff when piping the output to a non TTY device Possibly we might want to even move this to the |
|
@Crivella i tested your PR, but for some reason during the build the coloring is gone after the first line (found valid index for ...), and then comes back at the end (build succeeded for ...). adding any idea what's wrong? is this just me? |
|
For me it is working throughout all the build.
|
|
it's indeed the third case: something changes during the build so that i managed to fix it by using |
Co-authored-by: Sam Moors <smoors@users.noreply.github.com>
As far as i understand Do you know what in your case is causing this behavior? Some hooks overriding stdout or is it something internal to EB that you are triggering while i am not due to configs? |
i don't know what's causing this. i'm not doing anything special, i also disabled the hooks to be sure. what i did find out is that with |
Agree we should let the auto-detect do its work seems to work for me as well, gonna commit it and lets see the CI. |
| from rich.console import Console | ||
|
|
||
| console = Console() |
There was a problem hiding this comment.
suggestion to add some custom coloring
| from rich.console import Console | |
| console = Console() | |
| from rich.console import Console | |
| from rich.theme import Theme | |
| theme = Theme({ | |
| "success": "bold green", | |
| "fail": "bold red", | |
| }) | |
| msg = escape(msg) | |
| for regex in [r"(\[SUCCESS\])", r"(\[PASS\])", r"( OK)$"]: | |
| msg = re.sub(regex, r"[success]\1[/success]", msg) | |
| for regex in [r"(\[FAILED\])", r"(\[FAIL\])"]: | |
| msg = re.sub(regex, r"[fail]\1[/fail]", msg) | |
| console = Console(theme=theme) |
There was a problem hiding this comment.
I think if we want to add custom highlighting we should probably do so via a custom highlighter
Would not add the extra coloring in this PR.
At that point we could even define multiple themes to be used with the same highlighter for users to choose from (that would work very well in tandem with entrypoints so it becomes very easy to define a custom theme)
There was a problem hiding this comment.
I agree, we can revisit this in a subsequent PR.
I think it makes a lot of sense to use the success and fail tags that Rich supports, since I think that still allows for tweaking (through some Rich configuration).
This PR is a proof of concept for adding rich coloring to the console output printed through
print_msgRich will auto-recognize common patterns (eg dates, file paths) in the printed text and highlight them accordingly
Example:

NOTE:
Would need to adapt test to either not use
richor be aware of the coloring, otherwise most regex check on stdout will fail