Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.25k stars 1.72k forks source link

[question] How to use it with light background? #442

Closed jabbalaci closed 3 years ago

jabbalaci commented 3 years ago

I would like to use rich but by default it's made for dark background terminals. I prefer light background. How to set its color theme? Is there a config file for rich (or pygments) where I could change the color theme? Thanks.

willmcgugan commented 3 years ago

Rich works with light backgrounds. It will use the color theme set by your terminal software.

The Syntax class use pygments, and you can select any of the pygments themes there.

jabbalaci commented 3 years ago

Thanks. Well, it looks like this for me: https://i.imgur.com/kJPEoZy.png . I use Konsole with a light background. The "True" is hardly visible.

willmcgugan commented 3 years ago

That's using one of the 16 standard colors (bright green in this instance) set by your terminal. Whoever designed the light theme for Konsole decided that looked good on a white background, but I would agree with you that it lacks contrast.

I'd suggest picking another light color theme in Konsole. Or if you like, you can configure Rich with a custom theme.

>>> from rich.console import Console
>>> from rich.theme import Theme
>>> console = Console(theme=Theme({'repr.bool_true': "italic green"}))
>>> console.print(True, False, None)
jabbalaci commented 3 years ago

Thanks. I'm not good at creating an own style, but pygments has several styles:

>>> 
>>> from pygments.styles import get_all_styles
>>> 
>>> list(get_all_styles())
['borland', 'xcode', 'pastie', 'emacs', 'vim', 'rainbow_dash', 'igor', 
'algol', 'murphy', 'native', 'lovelace', 'algol_nu', 'rrt', 'arduino', 
'paraiso-dark', 'trac', 'fruity', 'colorful', 'friendly', 'vs', 'perldoc',
'autumn', 'monokai', 'abap', 'default', 'paraiso-light', 'tango', 'bw', 'manni']
>>> 
>>>

Is it possible to specify one of them for rich to use? Then I would try all and pick the one that looks best on my terminal.

willmcgugan commented 3 years ago

The Pygments theme applies to the Syntax class only. You would be better off find a theme for Konsole itself.

jabbalaci commented 3 years ago

Thanks. I tried all the Konsole light themes, but I don't like the result in any of them. Well, maybe I will try another terminal app., but Konsole was the best for me so far.

willmcgugan commented 3 years ago

iTerm is my favorite.

jabbalaci commented 3 years ago

I use Linux.