LCVcode / jockey

MIT License
2 stars 3 forks source link

Investigate using rich package to add color to Jockey outputs #20

Closed LCVcode closed 1 week ago

LCVcode commented 5 months ago

We should look into using rich as a way to spice up Jockey outputs to improve readability and generally make them more interesting/fun. I would like to see some example outputs from people who feel that outputs should be colored in a particular way.

Any work done here must not affect Jockey's ability to be piped into other commands. Pipeline compatibility is a first principle for this project.

Blocked by #19

johnlettman commented 5 months ago

Any work done here must not affect Jockey's ability to be piped into other commands. Pipeline compatibility is a first principle for this project.

I hard agree. To approach this, we will want to use the isatty call (e.g., sys.stdin.isatty()). Likewise, it does appear rich will make a best effort to do this automatically.

What is your opinion on using this to gate text formatting (e.g., readability indentation, etc.)? Suppose we have accurate detection of output capturing and redirection -- should we attempt to "prettify" the output when the user is the final reader of the output?

LCVcode commented 5 months ago

I think beautifying the output would be an excellent feature when humans are the final reader. One question that comes to my mind is how will this interact which Jockey outputs are set as a variable, which I would expect to see done quite frequently in playbooks and hopefully generally out in the wild.

UNITS=$(jockey units) need to not be beautified for the sake of scripting.

johnlettman commented 5 months ago

I created a small demo of the auto-detection to confirm our requirements here:

from rich.console import Console

console = Console()
print(f"color_system:     {console.color_system}")
print(f"is_terminal:      {console.is_terminal}")
print(f"is_dumb_terminal: {console.is_dumb_terminal}")

Using this, I can confirm that all of our expectations are covered.

Standard invocation (expect color)

Command
python3 ./rich-test.py 
Output
color_system:     truecolor
is_terminal:      True
is_dumb_terminal: False

Variable encapsulation (expect no color)

Command
test="$(python3 ./rich-test.py)"; echo "${test}"
Output
color_system:     None
is_terminal:      False
is_dumb_terminal: False

Piped stdout (expect no color)

Command

(note: on my system, cat is rebound to rcat)

python3 ./rich-test.py | rcat
Output
color_system:     None
is_terminal:      False
is_dumb_terminal: False