vis icon indicating copy to clipboard operation
vis copied to clipboard

Not all colors from the current theme are being used

Open acidrums4 opened this issue 1 year ago • 4 comments

Problem

There's something since 0.9 going on and it's bugging me out a bit: some (text) colors set in the current theme are not being used by vis.

I've noticed this specially with HTML files - for example, the HTML attributes are being painted with a color set for the shell/terminal emulator, green, rather than the colors set in the vis theme. No matter what theme is used, those are always being painted with the green color set for the shell/terminal emulator.

On the other hand, tabs are being painted with the default text color set in the vis theme rather than the color set by lexers.STYLE_WHITESPACE.

Steps to reproduce

  1. Use vis-0.9
  2. Open an HTML file
  3. Show tabs with set showtabs
  4. Set whatever theme for vis, even a default theme like solarized or zenburn

vis version (vis -v)

vis 0.9 +curses +lua +tre +acl

Terminal name/version

konsole 24.05.2

$TERM environment variable

xterm-256color

acidrums4 avatar Jul 26 '24 20:07 acidrums4

I've known about this for a while but I haven't invested the time to write a proper fix. There is an old assumption here: https://github.com/martanne/vis/blob/2d87fdc0d088b12571b0c695549106b766585a92/ui.h#L37 that the number of lexer styles is small but in new scintillua that does not seem to be the case. The function for defining styles returns a bool status but that is never checked in the lua code. HTML probably has more styles than the maximum and so a lot of them are just not getting stored and failing silently.

(Below is an outline of what I think should be done, I'm leaving it here as a good first issue for someone else to solve). UI_STYLE_LEXER_MAX should be increased and the lua code should check if it actually succeeds in defining the style. The maximum style id that gets defined should also be stored somewhere accessible from lua so that users/plugins that want to define their own styles know which slots are available. Also a test should be written that loops through the lexers and checks that they can successfully define all their styles (plus some headroom for users/plugin authors).

rnpnr avatar Jul 26 '24 22:07 rnpnr

I've known about this for a while but I haven't invested the time to write a proper fix. There is an old assumption here:

https://github.com/martanne/vis/blob/2d87fdc0d088b12571b0c695549106b766585a92/ui.h#L37

that the number of lexer styles is small but in new scintillua that does not seem to be the case. The function for defining styles returns a bool status but that is never checked in the lua code. HTML probably has more styles than the maximum and so a lot of them are just not getting stored and failing silently.

(Below is an outline of what I think should be done, I'm leaving it here as a good first issue for someone else to solve). UI_STYLE_LEXER_MAX should be increased and the lua code should check if it actually succeeds in defining the style. The maximum style id that gets defined should also be stored somewhere accessible from lua so that users/plugins that want to define their own styles know which slots are available. Also a test should be written that loops through the lexers and checks that they can successfully define all their styles (plus some headroom for users/plugin authors).

Something about whitespace handling seems to be inherently off, as this occurs with all filetypes i tested so far. Even increasing UI_STYLE_LEXER_MAX does not help.

dcallea avatar Sep 24 '24 11:09 dcallea

the HTML attributes are being painted with a color set for the shell/terminal emulator, green, rather than the colors set in the vis theme

Setting lexers.STYLE_ATTRIBUTE on my theme allowed me to change the colors of HTML attributes. Is this a theme issue then?

fre3nando avatar Sep 28 '24 02:09 fre3nando

Setting lexers.STYLE_ATTRIBUTE on my theme allowed me to change the colors of HTML attributes. Is this a theme issue then?

I'd like you to share your theme then, as I haven't been able to replicate that - as said, not even the default themes that are shipped with vis are using the colors set in the theme. Everyone paints HTML attributes with the same green from the terminal emulator theme (and "unknown" tags like <svg> with the same red from the terminal emulator theme.

acidrums4 avatar Oct 20 '24 00:10 acidrums4

I'd like you to share your theme then [...].

Hopefully I'm not so awfully late :/... I don't actually use that in my current theme (I'm using base16 atm). I just happened to notice that by browsing the source code. In any event, here's a sample theme to illustrate my point:

-- Eight-color scheme
local lexers = vis.lexers
lexers.STYLE_CLASS = 'fore:yellow,bold'
lexers.STYLE_COMMENT = 'fore:#545b67,italics'
lexers.STYLE_CONSTANT = 'fore:magenta,bold'
lexers.STYLE_DEFINITION = 'fore:blue,bold'
lexers.STYLE_ERROR = 'fore:red,italics'
lexers.STYLE_FUNCTION = 'fore:magenta,bold'
lexers.STYLE_KEYWORD = 'fore:blue,bold'
lexers.STYLE_LABEL = 'fore:green,bold'
lexers.STYLE_NUMBER = 'fore:yellow'
lexers.STYLE_OPERATOR = 'fore:white'
lexers.STYLE_REGEX = 'fore:green'
lexers.STYLE_STRING = 'fore:green'
lexers.STYLE_PREPROCESSOR = 'fore:magenta,bold'
lexers.STYLE_TAG = 'fore:red,bold'
lexers.STYLE_TYPE = 'fore:red,bold'
lexers.STYLE_VARIABLE = 'fore:magenta,bold'
lexers.STYLE_WHITESPACE = ''
lexers.STYLE_EMBEDDED = 'fore:green'
lexers.STYLE_IDENTIFIER = ''
lexers.STYLE_ATTRIBUTE = 'fore:#FF0000'

lexers.STYLE_LINENUMBER = 'fore:white'
lexers.STYLE_LINENUMBER_CURSOR = lexers.STYLE_LINENUMBER
lexers.STYLE_CURSOR = 'back:white,fore:black'
lexers.STYLE_CURSOR_PRIMARY = 'back:yellow,fore:black'
lexers.STYLE_CURSOR_LINE = 'underlined'
lexers.STYLE_COLOR_COLUMN = 'back:red'
lexers.STYLE_SELECTION = 'back:white'
lexers.STYLE_STATUS = 'reverse'
lexers.STYLE_STATUS_FOCUSED = 'reverse,bold'
lexers.STYLE_SEPARATOR = lexers.STYLE_DEFAULT
lexers.STYLE_INFO = 'fore:default,back:default,bold'
lexers.STYLE_EOF = ''

This uses the default terminal colorscheme for the most part, except of course:

lexers.STYLE_ATTRIBUTE = 'fore:#FF0000'

Which renders the HTML attributes red, regardless of the terminal colors. I found this at:

https://github.com/martanne/vis/blob/862c33fe0814ab7756aabcf55aa77fa9c3bd6ef2/lua/lexers/lexer.lua#L120

Environment:

  • $TERM: foot
  • vis -v: vis 0.9 +curses +lua +acl

fre3nando avatar Mar 18 '25 12:03 fre3nando

lexers.STYLE_ATTRIBUTE = 'fore:#FF0000'

Thank you, this did the trick - though in part. Non-standard html attributes (say, SVG attributes inside an HTML) are still painted console green, and non-html tags are still painted console red.

Though I guess I'll need to play a bit following this:

You may use your own tag names if none of the above fit your language, but an advantage to using predefined tag names is that the language elements your lexer recognizes will inherit any universal syntax highlighting color theme that your editor uses. You can also "subclass" existing tag names by appending a '.subclass' string to them. For example, the HTML lexer tags unknown tags as lexer.TAG .. '.unknown'. This gives editors the opportunity to style those subclassed tags in a different way than normal tags, or fall back to styling them as normal tags.

acidrums4 avatar Mar 30 '25 00:03 acidrums4

For what it's worth I ended finding out about #1196 (can't tell why I didn't saw that one when I opened this) and copied the changes they did to my themes, which solved pretty much every issue except the one about STYLE_WHITESPACE. Hope it can be fixed because that one is really annoying.

acidrums4 avatar Apr 10 '25 00:04 acidrums4

For what it's worth I ended finding out about #1196 (can't tell why I didn't saw that one when I opened this) and copied the changes they did to my themes, which solved pretty much every issue except the one about STYLE_WHITESPACE. Hope it can be fixed because that one is really annoying.

Care to elaborate, what’s the problem there, please?

mcepl avatar Apr 10 '25 06:04 mcepl