[REQUEST] Make it possible to join Syntax elements with different stylings.
See original GitHub issueHow would you improve Rich?
The feature request I would be interested is the ability to join Syntax
items so that different parts could be highlighted in a different theme. The desire to do so is to reproduce the highlighting recently introduced by IPython for indicating the location of the part of code that causes an exception as shown in a recent tweet; image below. This obviously cannot work if each Syntax
item appends a newline character by default as noted in #1827 … However, this feature request goes well beyond what is required to “fix” #1827.
In pseudo-code, and using a line of code from the image below, I would like to be able to do something like:
code = Syntax('return ', "python") + Syntax('x[0][i]', "Text only", theme="error") + Syntax('[0]')
print(code)
What problem does it solve for you?
Being able to reproduce the new styles of IPython tracebacks (including in Jupyter notebooks) to show the location of an error, instead of using a separate line and using ^
characters.
I already do this when showing tracebacks within IDLE (not supported by Rich).
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Syntax will grow the ability to highlight ranges of columns soon. Which should negate the need to join Syntax objects, which was always going to be problematic.
Did I solve your problem?
Why not buy the devs a coffee to say thanks?