sindrets/winshift.nvim

Colour name or number not recognised when in tty

Closed this issue · 7 comments

When in a tty, i.e. $TTY == /dev/tty*, an error involving unrecognised colours occurs. This is the error message:

Error detected while processing /home/bmr/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/bmr/.config/nvim/init.lua:71: /home/bmr/.config/nvim/init.lua..ColorScheme Autocommands for "*": Vim(lua):E5108: Error executing lua vim/_editor.lua:0: /home/bmr/.config/nvim/init.lua..ColorScheme Autocommands for "*"..script nvim_exec2() called at ColorScheme Autocommands for "*":0: Vim(highlight):E421: Colour name or number not recognised: ctermfg=#45403d ctermbg=#45403d
stack traceback:
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	...al/share/nvim/lazy/winshift.nvim/lua/winshift/colors.lua:126: in function 'hi'
	...al/share/nvim/lazy/winshift.nvim/lua/winshift/colors.lua:192: in function 'setup'
	[string ":lua"]:1: in main chunk
	[C]: in function 'colorscheme'
	/home/bmr/.config/nvim/init.lua:71: in main chunk
stack traceback:
	[C]: in function 'colorscheme'
	/home/bmr/.config/nvim/init.lua:71: in main chunk

Winshift commit: 37468ed
Neovim version: 0.9.1

I'm guessing you had 'termguicolors' enabled. That needs to be disabled in any context that doesn't support 24-bit colors. When 'termguicolors' is enabled nvim will internally translate all colors and return 24-bit color values from all the highlight API functions.

No, i have 'termguicolors' disabled in terminals without truecolor support, in particular in a tty.

Then you're gonna have to provide a minimal reproducible example, because I'm not able to reproduce it myself. Plugin works fine in tty for me.

Here's a template

Ok, I will produce an MWE as soon as I find the time. Thanks for the template!

Closing until requested info is provided.

This MWE reproduces the error if you start neovim twice:

-- ################################################
-- ### USAGE: nvim --clean -u winshift_mini.lua ###
-- ################################################

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################
vim.opt.termguicolors = false
vim.cmd.highlight 'Visual ctermbg=223 guibg=#eee0b7'

local id = vim.api.nvim_get_hl_id_by_name('Visual')
local attr = 'bg'

local value = vim.fn.synIDattr(id, attr)
print(string.format("synIDattr(%i, '%s') = %s", id, attr, value))

local root = vim.fn.stdpath("run") .. "/nvim/winshift.nvim"
vim.fn.mkdir(root, "p")

-- set stdpaths to use root
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "sindrets/winshift.nvim",
    config = true,
  },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}
require("lazy").setup(plugins, { root = root .. "/plugins" })
require("lazy").sync({ show = false, wait = true })

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################
value = vim.fn.synIDattr(id, attr)
print(string.format("synIDattr(%i, '%s') = %s", id, attr, value))

I traced the error in lua/winshift/colors.lua and it appears that the synIDattr() function behaves unexpected. It returns the guibg attribute despite termguicolors being disabled, illustrated by this MWE:

set notermguicolors
highlight Visual ctermbg=223 guibg=#eee0b7

echo 'Expected: synIDattr(25, "bg") = 223'
echo 'Actual: synIDattr(25, "bg") = ' . synIDattr(25, "bg")

I am not sure whether this behavior is inteded since syntax highlighting is enabled later in the startup procedure. Furthermore, it is strange that in the first MWE, the behavior of synIDattr() before and after the invocation of lazy differs.

To circumvent any unexpected behavior, one may specify synIDattr()'s third parameter (mode = "gui" or mode = "cterm"), depending on the whether termguicolors is enabled.

Bumping this as I have the same problem.