neovim-qt icon indicating copy to clipboard operation
neovim-qt copied to clipboard

Underline highlight is always red by default

Open mawkler opened this issue 2 years ago • 10 comments

When I use gui=underline in a highlight command without assigning a color using guisp the underline always gets the color red. When running Neovim in a terminal however, the default underline highlight seems to be the same value as fg.

mawkler avatar Sep 08 '21 14:09 mawkler

@Melkster

Thanks for the bug report! This is related to #851 and #856...

Previously we behaved like gVim, and always rendered underline in guifg. Now we try to respect guisp when available.

I would guess: you need to call :hi XYZ gui=underline guisp=None, otherwise the old guisp value can carry over.

Here is an example: :hi SpellBad :hi SpellBad gui=underline :hi SpellBad :hi SpellBad gui=underline guisp=None :hi SpellBad

Notice guisp=Red propagates even though it was not explicitly set in the second command.

I think we're behaving correctly here, and your TUI instance is not respecting the value of guisp. Some terminals are able to render underlines with guisp (Gnome Terminal), and others are not (Konsole). See 851 for more details.

I use console, so I see the similar underline behavior to you. However, I think Konsole's rendering is incorrect...

jgehrig avatar Sep 08 '21 18:09 jgehrig

If you still think there is a bug here after trying the suggestions above...

Please provide a minimal configuration and set of steps that demonstrates the issue: nvim-qt -- -u minimal.vim

Usually SpellBad is a good way to demonstrate highlight configuration issues.

jgehrig avatar Sep 08 '21 18:09 jgehrig

Thank you for your quick response! I tried using guisp=None but it makes no apparent difference.

I tried your example with :hi SpellBad gui=underline guisp=None with no config (nvim-qt -- -u NORC) but I'm still seeing red underlines.

Here's the output from running nvim-qt --version

NVIM-QT v0.2.17.9999
Build type: Release
Compilation:-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Wextra -Wno-unused-parameter -Wunused-variable -std=c++11
Qt Version: 5.15.2
Environment:
  nvim: nvim
  args: --cmd set termguicolors
  runtime:

NVIM v0.5.0
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/neovim/src/neovim-0.5.0/build/config -I/build/neovim/src/neovim-0.5.0/src -I/usr/include -I/build/neovim/src/neovim-0.5.0/build/src/nvim/auto -I/build/neovim/src/neovim-0.5.0/build/include
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

mawkler avatar Sep 08 '21 20:09 mawkler

What happens when you do the following:

  1. nvim-qt -- -u NONE
  2. Type "asdf", trigger mis-spelling
  3. :set spell
  4. :hi SpellBad (Output A screen-clip below)
  5. :hi SpellBad gui=underline
  6. :hi SpellBad (Output B screen-clip below)
  7. :hi SpellBad gui=underline guisp=None
  8. :hi SpellBad (Output C screen-clip below)

Output A image image

Output B image image

Output C image image

Does this match what you observe?

jgehrig avatar Sep 08 '21 21:09 jgehrig

Alternatively, if you have a case where the rendering is not correct...

It would be very helpful if you can provide an explicit set of steps where you start from nvim-qt -- -u NONE.

I'd like to see a case where :hi XYZ reports gui=underline and guisp as unreported or None, but the underline is still rendered red.

jgehrig avatar Sep 08 '21 21:09 jgehrig

I followed your steps, but in step 8 it looks like this to me 🤔

Screenshot from 2021-09-11 10-57-46

melkerulander-op avatar Sep 11 '21 09:09 melkerulander-op

Very strange! I can't explain this...

How did you build/install neovim-qt? What system is this on and is there anything unique about it?

Does :set notermguicolors do anything? (Steps 7/8 Only)

jgehrig avatar Sep 21 '21 03:09 jgehrig

I realize that I responded with my work GitHub account @melkerosterberg, so the version I'm using is the same one as mentioned in this comment, which I installed from the AUR.

I'm on a recent install of Manjaro Gnome that's not even a month old.

OS: Manjaro Linux x86_64
Kernel: 5.13.15-1-MANJARO
DE: GNOME 40.4

:set termguicolors makes no difference.

mawkler avatar Sep 21 '21 05:09 mawkler

No worries, I figured it was still you :)

I can't explain this... We don't hard-code the color red anywhere in the code except for invalid cells. Are you able to do some debugging?

I'm using 0.6.0, let's try testing with that version to eliminate variables.

A few ideas:

  1. Update nvim to the latest nightly. You can you nvim-qt --nvim and the latest nightly appimage here
  2. Let's hard-coding some values in ShellWidget::getSpecialPen(). Is the color specified by nvim for the highlight or fallback?
  3. Let's add some qDebug() statements to check the pen color in ShellWidget::paintUnderline().

jgehrig avatar Sep 23 '21 17:09 jgehrig

Adding some debug statements to paintUnderline shows the special pen color as being red QColor(ARGB 1, 1, 0, 0)

The method to get the pen (and set the color) does this

QPen ShellWidget::getSpecialPen(const Cell& cell) noexcept
{
	QPen pen;
	if (cell.GetSpecialColor().isValid()) {
		pen.setColor(cell.GetSpecialColor());
	} else if (cell.GetForegroundColor().isValid()) {
		pen.setColor(cell.GetForegroundColor());
	} else {
		pen.setColor(foreground());
	}

The cell special color is set as red, so we are taking the first branch.

I have check the calls, nvim emits the following calls

handleHighlightSet QMap(("background", QVariant(qulonglong, 3815994))("bold", QVariant(bool, true))("foreground", QVariant(qulonglong, 14934231))("special", QVariant(qulonglong, 16711680)))
  • this sets special QColor(ARGB 1, 1, 0, 0)

then we receive an empty event

handleHighlightSet QMap()
  • but this does nothing to special, it remains as QColor(ARGB 1, 1, 0, 0)

Finally we see the event that enables the underline

handleHighlightSet QMap(("background", QVariant(qulonglong, 3815994))("foreground", QVariant(qulonglong, 14934231))("underline", QVariant(bool, true)))
  • special is still red at this point

equalsraf avatar Feb 06 '22 00:02 equalsraf

@melkster

It looks like this issue is related to how colors are rendered when ext_linegrid is disabled.

You should be able to fix this issue by setting ~/.config/nvim-qt/nvim-qt.conf:

[General]
ext_linegrid=true

See #1011

jgehrig avatar Oct 01 '22 15:10 jgehrig