Replies: 1 comment
-
There isn't anyway to highlight columns at the moment, but it shouldn't be difficult to add. There is a At some point I might add a method to do that, but it's not high on my list ATM. Would be happy to accept a PR if you would like to tackle it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey folks,
I just discovered Rich and it is amazingly useful! I have been using it to make output from a DSL compiler much, much nicer!
I am using rich.syntax.Syntax to style the output with language syntax highlighting via pygments which works very nicely. It especially works great at handling word wrapping, line numbers, and adding indentation markers!
However, there is one thing that I haven't figured out a way to do is highlight specific columns. Once a Syntax object has been created, there doesn't appear to be any way to further modify the output. The best idea I had was to inject special highlight tokens and then make modifications to the pygments lexer. (I haven't tried this yet, but it will probably work.)
This isn't a show stopper in any case, of course, because I am pointing to the error columns by printing a line with carets (^) underneath. But I would really like to be able to highlight specific columns of certain lines.
I don't know what the best API would be, but I kind of image that it could be an enhancement to hightline_lines. Currently this is a set of line numbers. But perhaps it could take a set of line numbers OR tuples of (line number, start, end) where start and end are where to start and end highlighting on the line. (It would be ideal if start and end were in terms of user-visible columns (Unicode extended grapheme clusters) and I think Rich is already pretty smart about that, but even if it were just start/end codepoint that is no problem for me at least.)
Anyway, I will probably solve this in my own code by using a pygments lexer trick with special synthesized tokens marking the error, but I would really love to see this as a feature in Rich. Besides my use case, I could see this being useful for other purposes, basically any time it is useful to call out a specific region of source code.
In any case, thanks for making such a great library.
Beta Was this translation helpful? Give feedback.
All reactions