Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow independent coloring of underline in supported terminals #2405

Closed
wants to merge 2 commits into from

Conversation

avernan
Copy link

@avernan avernan commented Dec 3, 2017

This uses the new option termguiul and the new (proposed) termcap option t_8u which should behave analogously to t_8f and t_8b. This is supported (and inspired) from kitty (by @kovidgoyal), as mentioned in #1306 .
Since most terminals will not support this at the moment, I left the default value of t_8u as an empty string.

To test this feature in kitty, you can use the following minimal .vimrc

let &t_8u = "\<Esc>[58;2;%lu;%lu;%lum"
set spell
hi SpellBad cterm=underline ctermbg=NONE guisp=#AB3434
set termguiul

This uses the new option `termguiul` and the new (proposed)
termcap option `t_8u` which should behave analogously to `t_8f` and
`t_8b`.
I set the default termcap option to empty as this is not a widely
supported feature, so most terminals will not support it.
@kovidgoyal
Copy link

@avernan Cool, thx, implementing this in vim was on my TODO list. Just to note, it's possible the code for selecting the underline style might change based on feedback from the VTE developers. See neovim/neovim#7479 for discussion.

@avernan
Copy link
Author

avernan commented Dec 3, 2017

@kovidgoyal That discussion is part of the reason why I haven't set a default code.

@brammool
Copy link
Contributor

brammool commented Dec 3, 2017 via email

@egmontkob
Copy link

FYI: VTE has just received this feature in git, using the same SGR 58 and 59 as Kitty.

@brammool brammool added the needs more work used for a pull request that isn't ready to include (other than needing a test) label May 9, 2019
@brammool
Copy link
Contributor

Closing, since there was no progress for a long time. The solution I requested is different anyway.

@brammool brammool closed this Sep 27, 2019
ajvondrak added a commit to ajvondrak/vondark that referenced this pull request Jan 12, 2021
Terminals have only recently started supporting undercurls, due to the
xterm extensions advanced by the Kitty terminal emulator. So clearing
the terminal defaults for the Spell* groups (per ccaf8de) just left
them with no highlighting whatsoever in the terminal. I found this was
the only case where gui and guisp weren't translating over as I wanted.

First off, you have to use cterm=undercurl, not just gui=undercurl. Even
then you have to make Vim output the right escape sequences to the
terminal with

  let &t_Cs = "\e[4:3m"
  let &t_Ce = "\e[4:0m"

I of course won't set those directly from the color scheme, since it's
not a given that your terminal will support the escape codes. Though to
their credit, most terminals seem to at least gracefully fallback to
straight underlines.

But even with curly underlines, it doesn't seem like many macOS
terminals actually support coloring the underline separately from the
foreground. Although Kitty supports it just fine (and I should hope so,
being the project that promoted this feature), I've found that neither
iTerm2, Alacritty, nor Hyper could render differently-colored undercurls
in Vim. And I can't really find any other high-profile macOS terminals,
so in my mind Kitty is the only one where this works! (There seems to be
some evidence floating around that neovim does something different to
get undercurls right, maybe? But I don't really understand it, and I'm
not about to go down that rabbit hole.)

There also doesn't seem to be a good way to automatically detect if a
terminal supports colored undercurls. So, I'm just going with the better
safe than sorry approach, which at least works in my current terminal of
choice (iTerm2). Namely:

1. Make sure to set cterm=undercurl as well as gui=undercurl. As a
   general extension, I think it's true that we want to set cterm to
   whatever attributes I use for the gui (across the whole color scheme,
   I only use undercurl and bold), so it's natural to just stick this in
   s:hi directly.

2. As a compromise, the terminal will use guifg instead of guisp for the
   Spell* groups. That way, we'll get *some* sort of color onto the
   screen, albeit for the whole word + the undercurl instead of only for
   the undercurl. I can't do this in a single call to s:hi, though,
   because I don't want to use guifg when the GUI is running (it can
   just can make proper use of guisp). So I wrap the Spell* groups in a
   gui_running check.

This is the only case I found in the whole scheme that needed a fallback
plan for terminal support. Otherwise, termguicolors seems to take care
of the rest.

Further reading:
* https://sw.kovidgoyal.net/kitty/protocol-extensions.html
* https://gitlab.com/gnachman/iterm2/-/issues/6382
* vim/vim#1306
* vim/vim#6687
* vim/vim#2405
* neovim/neovim#7479
* alacritty/alacritty#1628 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more work used for a pull request that isn't ready to include (other than needing a test)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants