Re:Make Your Python CLI Tools Pop with Rich
by TylerE on Thursday January 20, 2022 @09:04PM
(#30018301)
Question: How horribly does the world break if you pipe the output to a file instead of stdout?
Re:Make Your Python CLI Tools Pop with Rich
by varenc on Thursday January 20, 2022 @10:31PM
(#30018801)
Not at all! Like many CLI tools, it turns off the formatting when it detects you're not outputting to a terminal.
Here's where it checks: https://github.com/Textualize/rich/blob/5a457bfbc662ab8701dc... (and I just tested to confirm it does indeed work)
Re:Make Your Python CLI Tools Pop with Rich
by windexh8er on Thursday January 20, 2022 @09:32PM
(#30018483)
Rich McGugan (author of Rich) talks about a lot of different design aspects of Rich on an episode of Talk Python [0] last October. I've used it in a few projects since then and for what I've been using it for the output is still easily consumable. Rich is a game changer for output in Python and it pairs nicely with CLI libs like Click. McGugan also is putting a lot of effort into Textual [1] which is fantastic for TUI apps.
[0] https://talkpython.fm/episodes/show/336/terminal-magic-with-... [1] https://github.com/Textualize/textual
Re:Make Your Python CLI Tools Pop with Rich
by willm on Friday January 21, 2022 @02:41AM
(#30020395)
*Will McGugan :)
Re:Make Your Python CLI Tools Pop with Rich
by windexh8er on Friday January 21, 2022 @10:34AM
(#30024920)
Oh man, fail on my part. Apologies Will! I think now's a great time for me to donate. ¯\_(ツ)_/¯
Edit: Tried to sponsor your linked Ko-fi from what's listed in the rich repo, but the link provided doesn't work and searching your name doesn't pull anything up. Sent you an email to find a better way.
Re:Make Your Python CLI Tools Pop with Rich
by eyegor on Thursday January 20, 2022 @09:09PM
(#30018335)
I would assume the lib authors accounted for this, it's pretty easy to check with sys.stdout.isatty(). If not you could alias it yourself.
Re:Make Your Python CLI Tools Pop with Rich
by willm on Friday January 21, 2022 @02:40AM
(#30020387)
Glad you find it useful!
Re:Make Your Python CLI Tools Pop with Rich
by bikingbismuth on Thursday January 20, 2022 @08:44PM
(#30018135)
Thanks for the suggestion. I occasionally add progress % to some of my scripts, but anything more advanced I can’t be bothered. Excited to check out the library, thanks for the print() suggestion.
Re:Make Your Python CLI Tools Pop with Rich
by jszymborski on Thursday January 20, 2022 @08:44PM
(#30018137)
I so appreciate the little things, like `console.log` printing not only discretely naming the filename and line, but also providing a link to it.
Every one of my scripts now has quick and easy progress bars, console management (including saving a copy of console output), tables with columns, rows, and headers, "Processing..." blocks, colours, error logging, emoji, and on and on and on. It's really an amazing project that does a ton of stuff and makes it all easy to do.
If nothing else, add "from rich import print" to the top of your script (assuming you use print() statements) and see how your output looks afterwards, with highlighted numbers/floats, IP addresses, etc., formatted and syntax-highlighted JSON and repr output, and so on.