Force rich to use the style I specity for braced output in f-strings #2072
-
Probably a stupid newbie question, probably answered in the RTFM, but I couldn't see it quickly. I'm doing this: console.print(f'{testsRun:5,} Run ', style='black' end='')
console.print(f'{nf:5,} F ', style='red' if nf else 'black', end='')
console.print(f'{ne:5,} E ', style='purple' if ne else 'black', end='')
console.print(f'{ns:3} S {c.__name__}') and was hoping (and expecting) that the numbers in the f-strings would come out in the colour I specify. But they don't: they mostly come out in a sort of dull cyan (and bold, I think). Can I force them to come out in the colour/style I say? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Rich will highlight numbers and a bunch of other things automatically. You can switch that off with |
Beta Was this translation helpful? Give feedback.
-
Perfect! And then I can leave the style as blank, rather than black, and get the default colour. Brilliant. Sorry, I'm sure if I'd RTFM'd more I'd have found that. Excellent stuff! |
Beta Was this translation helpful? Give feedback.
-
In case you're interested, this is what I end up with: (It's a parallel test runner.) I know it's not very colourful at the moment, but when I break the build, there'll be colour all over the place! |
Beta Was this translation helpful? Give feedback.
Rich will highlight numbers and a bunch of other things automatically. You can switch that off with
highlight=False
on theprint
method, or in the Console constructor.