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

Themes with highlight groups using "links" to other groups do not propagate colors to SwiftUI properly #1069

Open
s-daveb opened this issue May 28, 2024 · 2 comments

Comments

@s-daveb
Copy link
Contributor

s-daveb commented May 28, 2024

I think I figured out why another bug where some themes do not propagate their theme colors to VimR, such as dracula.

I noticed color changes are propagated from
In NvimView+Resize.swift, line 129

autocmd ColorScheme * call rpcnotify(\(channel), 'autocommand', 'colorscheme', get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('TablineSel')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('TablineSel')}), 'fg', -1))

But when I try to get those specific groups in neovim:

echo get(nvim_get_hl(0, {'id': hIID('TablineSel')}, 'fg') 
['bold': vitrue, 'cterm': {'bold': vitrue}, 'link': 'Normal'})

echo get(nvim_get_hl(0, {'id': hIID('TablineFill')}, 'fg') 
({'link': 'DraculaBgDark'})

Because some themes define highlight groups that pull their values from other groups ("link" to other groups), when using the existing code, get(nvim_get_hl(0, {'id': hlID('TablineFill')}), 'bg', -1), the result with these highlight groups is always -1.

Reading up on highlight groups in the neovim docs, they suggest using something more like synIDattr(synIDtrans(hlID('TablineFill')),'bg').

Trying it in my clients, I get:

echo synIDattr(synIDtrans(hlID('TablineFill')),'bg')
#21222c

echo synIDattr(synIDtrans(hlID('TablineFill')),'fg')

This is a lot better, returning with hex color codes starting with #, but it results in empty strings when there is no value set, which could affect how existing code handles missing color codes.

I'm working on a pull-request that changes how the colors are grabbed, without changing how their error handling ( value of -1 ) works; but I wanted to also have this issue to explain the problem.

@georgeharker
Copy link
Collaborator

georgeharker commented May 28, 2024 via email

@s-daveb
Copy link
Contributor Author

s-daveb commented May 28, 2024

@georgeharker That's not a bad suggestion, but where possible, it's probably best to let the neovim runtime do all the hard work.

I found that using the builtin funtionss as such follows all links automatically:

synIDattr(synIDtrans(hlID(<GroupName>)), <fg|bg>) " -> returns '#rrggbb' or ''

I got the following vimscript function to behave like get() when the result is not found

function! GetHiColor(hlID, component)
  let color = synIDattr(synIDtrans(hlID(a:hlID)), a:component)
  if empty(color)
    return -1
  else
    return str2nr(color[1:], 16) "removes leading # and converts hex string to its int value
  endif
endfunction

echo GetHiColor('TabLineFill', 'bg')   " -> 2171436
echo get(nvim_get_hl(0, {'id': hlID('TabLineFill')}), 'bg', -1)  " -> -1

Screenshot 2024-05-28 at 2 22 56 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants