ap / vim-css-color

Preview colours in source code while editing
http://www.vim.org/scripts/script.php?script_id=5056
MIT License
1.79k stars 80 forks source link

Text of dark colors is illegible #129

Closed mb720 closed 4 years ago

mb720 commented 4 years ago

Hi and thanks a lot for this plugin!

If the color name "black" occurs in a CSS file, I can't read it anymore since it's become a black stripe.

For example, I have this rule in a CSS file:

  kbd
    {
    -moz-border-radius:3px;
    -moz-box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset;
    -webkit-border-radius:3px;
    -webkit-box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset;
    background-color:#f7f7f7;
    /* Names of dark colors like black are illegible */
    border:1px solid #ccc;
    border-radius:3px;
    box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset;
    color:#333;
    display:inline-block;
    line-height:1.4;
    margin:0 .1em;
    padding:.1em .6em;
    text-shadow:0 1px 0 #fff;
  }

On my machine, this looks like something the CIA released ;-)

CSS rule

I'm using Neovim inside Kitty as the terminal emulator.

I have this in my kitty.conf:

foreground #204040
background #f7f5cd

While I was scrolling through the file, the colors suddenly worked:

CSS rule legible

This lasted only a briefly. After scrolling to the top of the file and back down to this CSS rule, the color names were illegible again.

Please let me know how to debug this.


I tested it with a different terminal emulator, Konsole, seeing the same results.

ap commented 4 years ago

The plugin already tries to prevent that from happening. It calculates the brightness of the colour and sets the text colour to black if the colour is light, or white if the colour is dark. That’s what all the variables with “bright” in their name are for.

Does Vim consider your terminal a 256-colour terminal? Because in that case the plugin uses colour 0 for black and colour 15… but of course those indices could be anything. If you’re defining a custom background and foreground colour it could be that the terminal emulator is putting them in those spots in the palette. OTOH, the rectangle on the screenshot is pure #000000, no trace of #204040, so that doesn’t seem right either. I don’t know what’s going on exactly.

mb720 commented 4 years ago

Does Vim consider your terminal a 256-colour terminal?

I'm not sure. echo $TERM gives xterm-kitty. If I do export TERM=xterm-256color; before opening the file, it doesn't seem to have an effect.

I just tested with Konsole and Alacritty again and can see that the dark colors are highlighted properly. But when I scroll down to the CSS rule mentioned above, all syntax highlighting is lost, in all terminal emulators. When I scroll back up, everything's fine in Konsole and Alacritty, but in Kitty, I see those black bars instead of color names. Seems like an issue with Kitty.

It also might be, that I'm observing two unrelated phenomena.

I'm closing this for now since in the majority of tested terminal emulators it works.

ap commented 4 years ago

Why closed…?

mb720 commented 4 years ago

Because I don't think the issue lies with the plugin, but rather with Kitty. I can reopen if you want.

ap commented 4 years ago

Ah. That’s fine then.