-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Sometimes use console.print render table instance with keywords #987
Comments
Take a look at escaping. What is your desired output? from rich.console import Console
from rich.table import Table
from rich.markup import escape
cons = Console(width=100)
a = "[#######.................] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [#######.................]"
t = Table(title=f"xxx")
t.add_column("Output", justify="full", style="cyan", overflow="fold")
t.add_row(escape(a))
cons.print(t) Rich is trying to interpret the brackets as markup styling. Not sure why it stops erroring when the console width is significantly increased. |
Thanks @nathanrpage97 The markup is parses a style as "######.............", which doesn't exist and is omitted from the output. But when the text wraps it calls the method So there is an inconsistency there. It shouldn't matter if it wraps. I think the fix would be to be a bit stricter about the parsing. If the style starts with a # and isn't a valid hex color, then it should raise a markup syntax error. @b3wsh Nathan is correct, if your string looks like console markup, but isn't, you can escape it. Or use Text class, ie. |
Tanks @nathanrpage97 and @willmcgugan for your solutions. I have resolve my problem. As @willmcgugan said, there is an inconsistency there, though Rich has provided escape method. Do you think we need some change to make style parsing more robust? |
There will be a fix in the next version. |
Thank you for your excellent job, I have tried to solve this, but do not find a better way, just wanna for some good code to learn. Thanks! |
Describe the bug
Sometimes use console.print render table instance with keywords
[
, rich will crash. example under below.ps:
if I change Console param width size bigger than
a
's length, this crash will disappear, at the same change thea
's length little thanwidth
size, at the same as canceljustify
oroverflow
param of add_column.I thought this problem cause by words split when rendering table, and then use "####" to search style.
To Reproduce
Platform
full platform
Diagnose
The text was updated successfully, but these errors were encountered: