-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Formatting error when printing via rich.console #54
Comments
Thanks for the extra context.
This has to do with your console trying to wrap the output to fit the console width (the console width is by default set to the width of your terminal). Note that the formatter's output is wrapped by the formatter itself, not by the internal console and shouldn't be wrapped by the external console. This is how argparse formatters work (
This has nothing to do with the internal console, it just return the text as a string. The same wrapping issue would happen if you console print any long text that contains new lines and leading spaces. If you follow solution 2 above, your problem will be solved. I'll close this issue as no action has to be taken in |
This is a new approach that allows the formatter itself to be rendered with rich. The handling of whitespace manipulation and wrapping is now baked into the renderable itself. This also removes the need to use `soft_wrap=True` when printing the formatted help. The downside is that the code is now very low-level in terms of rich rendering, it needs to do line-by-line handling of `Segment` objects. This could help unblock more niche use-cases like #81 and #54.
This is a new approach that allows the formatter itself to be rendered with rich. The handling of whitespace manipulation and wrapping is now baked into the renderable itself. This also removes the need to use `soft_wrap=True` when printing the formatted help. The downside is that the code is now very low-level in terms of rich rendering, it needs to do line-by-line handling of `Segment` objects. This could help unblock more niche use-cases like #81 and #54.
When printing the results of
format_help()
from an argparser that usesRichHelpFormatter()
as a formatter, the output is not formatted correctly if those results are printed usingrich.console.Console
. I've created a program which reproduces this problem:Here's a screenshot of the output:

Note that when the output is printed using
console.print(prsr.format_help())
the help text for the single positional argument does not wrap correctly.My current (untested) hypothesis is that this has something to do with having nested
rich.console
objects. The current implementation offormat_help()
uses the.capture()
context manager to collect the output before returning.The text was updated successfully, but these errors were encountered: