Skip to content
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] Cosmetic bug for __rich_repr__ repr-error #1326

Closed
aroberge opened this issue Jul 4, 2021 · 4 comments
Closed

[BUG] Cosmetic bug for __rich_repr__ repr-error #1326

aroberge opened this issue Jul 4, 2021 · 4 comments
Labels
accepted Task was accepted bug Something isn't working

Comments

@aroberge
Copy link

aroberge commented Jul 4, 2021

I'm sorry, I tried to come up with a simple example, but I could not create a simple example that generated a repr-error. I'm using Rich 10.4.0 and (ab)use __rich_repr__ to create some translatable help.

Basically, when a repr-error is generated, it contains an item enclosed in single quotes. This item can contain terms that are also enclosed in single quotes. If so, the result is not highlighted properly.

image

For info, here's what it looks like when I fix the error in my code, using my own colour scheme (I love this feature of Rich)

image

@willmcgugan
Copy link
Collaborator

Easy fix, will be in the next version.

I wonder if I should offer alternative themes in Rich...

@willmcgugan willmcgugan added accepted Task was accepted bug Something isn't working and removed Needs triage labels Jul 4, 2021
@aroberge
Copy link
Author

aroberge commented Jul 4, 2021

Regarding additional themes: I found it easy enough to design my own themes - although I did have to dig up in the code to figure out some "repr" attribute names, like repr.bool_true.

If I were you, I would just invite people to design their own themes, and provide links.

One thing that I am not too fond of in the default theme for Rich when using Pygments for highlighting some code blocks is that, by default, Rich uses three different colours for True, False, and None for their "repr" while Pygments uses a single colour for all three. So, depending on how True/False/None are processed, they can show up in different colours in the terminal. For example, in your README, we can see True and False showing up in light blue in a code block on the left-hand side, and respectively green and red on the right-hand side. I think I understand why you chose to use different colours for these three singletons, but I prefer a single colour myself.

@willmcgugan
Copy link
Collaborator

Should be fixed in 10.5.0

I find the different highlighting of True / False / None helps when scanning a data dump. The color alone is enough to know what it is.

I see your point that the styles don't match syntax highlighting. In tracebacks I forced the reprs to use the colors from the Pygments theme, because the difference is more jarring when the two are right next to each other. But for printing data structure I find the utility of the default theme to be worth it.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jul 5, 2021
10.5.0:

Fixed

Fixed Pandas objects not pretty printing Textualize/rich#1305
Fixed Textualize/rich#1256
Fixed typing with rich.repr.auto decorator
Fixed repr error formatting Textualize/rich#1326

Added

Added new_line_start argument to Console.print
Added Segment.divide method
Added Segment.split_cells method
Added segment.SegmentLines class
@aroberge
Copy link
Author

aroberge commented Jul 7, 2021

Sorry for not replying sooner: as far as I can tell from my tests, it is fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Task was accepted bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants