nvim-tree / nvim-web-devicons

lua `fork` of vim-web-devicons for neovim
MIT License
2.09k stars 185 forks source link

checking cterm color pollutes `redir` command #169

Closed rebelot closed 1 year ago

rebelot commented 2 years ago

Hello, I've noticed that nvim-web-devicons get_icon_* pollutes vim command output with what seems to be a spurious execution of :hi <hl_group> with no arguments. This causes problems when using the :redir command because get_icon_* functions are usually called by statusline plugins, which fire while :redir is registering the output of a command.

steps to reproduce:

:redir @a
:lua =require("nvim-web-devicons").get_icon_color('test.py', 'py') 
:redir END
:echo @a

produces

DevIconPy      xxx ctermfg=61 guifg=#ffbc03
""    "#ffbc03"

expected behaviour

the snippet above should only produce

""    "#ffbc03"

solution

I think this is the offending line

https://github.com/nvim-tree/nvim-web-devicons/blob/9061e2d355ecaa2b588b71a35e7a11358a7e51e1/lua/nvim-web-devicons.lua#L1656

I think cterm color could be retrieved using, for example, nvim_get_hl_by_name('DevIconPy', false).foreground