walles / moar

Moar is a pager. It's designed to just do the right thing without any configuration.
Other
600 stars 17 forks source link

syntax highlighting unreadable on light background #60

Closed plgruener closed 3 years ago

plgruener commented 3 years ago

Moar seems to hardcode some (but not all) of its colors. For example a light grey is used for variables and function arguments, but this is almost invisible when using a light background color. Not all Terminals have white font on black background.

Easy-ish solution: don't use hardcoded rgb- or 256-color values anywhere, exclusively use one of the 16 colors set by the terminal. This ensures moar's colors change accordingly when the terminal's colorscheme changes.

(Note: I know dealing with syntax highlighting and colorschemes is hard, especially if you want to support a growing number of programming languages and user-customizable colorschemes (with more than 16colors). I could possibly write you a little summary on how to deal with this, if you're interested.)

walles commented 3 years ago

moar uses Chroma, which has a sizable number of themes: https://xyproto.github.io/splash/docs/longer/all.html

I think the correct solution here would be to:

  1. Add a -theme=paraiso-light command line option
  2. On startup, pick command line options from a MOAR environment variable

If you got that, do you think your problem would be solved?

plgruener commented 3 years ago

No, only partially. All the themes in Chroma have, as far as I can tell, hardcoded 24bit RGB colors.

What I really want is a colorscheme – either a) included per default and/or b) loadable at runtime from a user-defined config file – that has no own colors, but only the common 16colors (black, red, green,…, bright-red, bright-green,…) and generates the appropriate 4bit ANSI escape codes (eg \e[31m for a generic "red"). The mapping of those 16colors to their respective rbg-values is already done by my terminal. That has several advantages: virtually all color-capable programs support those 16colors (but many still don't have 24bit color support), and I can change the colors of all my applications by simply changing the mapping in my terminal. (This allows eg. to quickly switch from a light scheme during the day to a dark one at night.)

Your proposed option would not work, because the colors of the themes Chroma includes may or may not match those of my terminal.

I'd even argue that this 4bit – or ANSI-exclusive, if you will – colortheme should be the default for moar: black-text-on-light-background terminals are not unheard of, they are even the default for some distros. That means new users encountering moar would think it is unusably broken, see screenshots below. Using only the 4bit colors however ensures that the syntax highlighting is always readable, no matter what terminal theme the user has.

moar3 moar4

In this screenshot, I've set my terminal to red text on black background. You can see on the line numbers that red default text is respected in some places, but not all. moar5

walles commented 3 years ago

Cool, thanks for the info!

FWIW, moar's own UI only uses default foreground and default background colors, so that's why the status bar and the line numbers are red.

Source code coloring on the other hand is done by Chroma in RGB.

How about this then?

Ref: https://github.com/alecthomas/chroma/blob/2bcdf19ee22749d0c060f7fb538c1e8c5b2f4715/formatters/tty_indexed.go#L262-L282

walles commented 3 years ago

@plgruener I implemented the solution in https://github.com/walles/moar/issues/60#issuecomment-839441554.

In your case, doing export MOAR="-colors=16" in some init script before invoking moar that should get you the behaviour you want.

If this does not help, feel free to comment / reopen.