Provide a context manager for automatically setting indentation levels when printing #1424
Unanswered
ruancomelli
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, everyone! Before anything else, I'd like to compliment you all for this awesome project and community.
What
I'd like to discuss with you the possibility of including a context manager for automatically indenting text. For instance, the snippet
should output
Of course, one should be able to customize the indentation characters, and the context manager should be reentrant:
Output:
Why
More than once, when writing (very small) CLI applications, I got something along the following lines:
But things get complicated very fast because of that
indentation
parameter that has to be passed around all the time. If I could customize the indentation level outside of the function (in theconsole
object, for instance), and have only theconsole
itself being forwarded between functions (or even define it globally, as I do in most cases), things would look much simpler:How
I'm really a newbie to Rich, so I won't even guess how to start implementing such functionality. I'll leave feasibility/difficulty/usefulness for you people to judge 😁
But, if you are interested, I have a draft implementation here:
It works almost as expected, except that
IndentableConsole.print
inserts asep
between the indentation marks and the text we want to print. I believe it is just a matter of playing with the arguments, but I haven't taken the time to do it yet.Beta Was this translation helpful? Give feedback.
All reactions