psyinfra / onyo

text-based inventory system on top of git
ISC License
3 stars 5 forks source link

Bug: `onyo cat` syntax highlighting is unreadable in some terminals #706

Open aqw opened 3 weeks ago

aqw commented 3 weeks ago

Depending on the terminal color scheme, the syntax highlighting can be either wonderful, or entirely illegible.

The color theme should be configurable by the user. Rich.Syntax uses Pygments Styles.

I propose adding a flag and config option:

onyo cat --style monokai <asset>

And the config:

[onyo "cat"]
    style = monokai

The current default (inherited from Rich) is monokai.

It may be necessary also to look at Rich.Syntax's background_color:

background_color (str, optional) – Optional background color, or None to use theme color. Defaults to None.

In addition to available styles, we should allow 'none' (or 'disable') to turn off syntax highlighting in cat.

To list available styles:

In [1]: from pygments.styles import get_all_styles
In [2]: list(get_all_styles())
Out[2]: 
['abap',
 'algol',
 'algol_nu',
 'arduino',
 'autumn',
 'bw',
 'borland',
 'coffee',
 'colorful',
 'default',
 'dracula',
 'emacs',
 'friendly_grayscale',
 'friendly',
 'fruity',
 'github-dark',
 'gruvbox-dark',
 'gruvbox-light',
 'igor',
 'inkpot',
 'lightbulb',
 'lilypond',
 'lovelace',
 'manni',
 'material',
 'monokai',
 'murphy',
 'native',
 'nord-darker',
 'nord',
 'one-dark',
 'paraiso-dark',
 'paraiso-light',
 'pastie',
 'perldoc',
 'rainbow_dash',
 'rrt',
 'sas',
 'solarized-dark',
 'solarized-light',
 'staroffice',
 'stata-dark',
 'stata-light',
 'tango',
 'trac',
 'vim',
 'vs',
 'xcode',
 'zenburn']

Open Question:

TobiasKadelka commented 3 weeks ago

I like the ideas for the flag and the option, it makes a lot of sense to me.

I have no strong oppinions about default colors. Of course it makes sense to select something that works for most configurations, i.e. a strong contrast between writing and background, and there are still discussions in the chat going on about transperancy, but in the end... This might be a good oportunity for us to test in the group to usage of local config files.

bpoldrack commented 3 weeks ago

I think the default should actually be something that does not use colors, but only bold, underlined, italic .. attributes. It's the only thing that should work everywhere and for everyone.

We need a pretty generic config mechanism for this and figure out how to also apply that to other outputs including help. So, we may end up with more generic config-override options. However, --style could then become an alias, so I'm fine with it as a quick solution for cat right now. But figure out how we want to implement it more generally before spreading that option to other commands.

aqw commented 3 weeks ago

I think the default should actually be something that does not use colors, but only bold, underlined, italic .. attributes. It's the only thing that should work everywhere and for everyone.

I agree.

We need a pretty generic config mechanism for this and figure out how to also apply that to other outputs including help.

Oof. Good point. That one... will be difficult and may require its own issue. @j-leo you're the one running a terminal with a bright background. How is the legibility of the text (and colorized text) in onyo set --help?

Looking at the highlighting in a complex one (onyo set --help, the color style changes between the help text and the code blocks. There's already room for improvement and standardizing there.

j-leo commented 2 weeks ago

I think the default should actually be something that does not use colors, but only bold, underlined, italic .. attributes. It's the only thing that should work everywhere and for everyone.

I agree.

We need a pretty generic config mechanism for this and figure out how to also apply that to other outputs including help.

Oof. Good point. That one... will be difficult and may require its own issue. @j-leo you're the one running a terminal with a bright background. How is the legibility of the text (and colorized text) in onyo set --help?

Looking at the highlighting in a complex one (onyo set --help, the color style changes between the help text and the code blocks. There's already room for improvement and standardizing there.

onyo set --help looks good IMO: image