feat(tui): $NVIM_TERMDEFS can override builtin terminfo #39555

Problem:
- Windows users can't use terminfo to configure their terminal
  capabilities. #37274
- Terminfo definitions sometimes get out of date or are simply
  inaccurate.
- Eventually, we may want to drop terminfo, relying primarily on
  built-in definitions. Users will still need some flexibility.

Solution:
Support $NVIM_TERMDEFS environment variable, which is JSON data that
defines "terminfo" definitions that override our builtin terminfo.
This commit is contained in:
Kyle
2026-05-17 12:02:46 -05:00
committed by GitHub
parent fff9897ce3
commit 84d5c5f4bf
11 changed files with 613 additions and 223 deletions

View File

@@ -158,4 +158,30 @@ function M.query_apc(payload, opts, on_response)
end)
end
--- Displays error even when this code runs in the context of the client
--- @param msg string
local function broadcast_error(msg)
vim.rpcnotify(0, 'nvim_echo', {
{
msg,
},
}, true, { err = true })
end
--- Get user overrides for terminfo entries as a table. See |$NVIM_TERMDEFS|
function M.get_termdefs()
local termdefs_raw = os.getenv('NVIM_TERMDEFS')
if termdefs_raw ~= nil then
local ok, termdefs_or_err = pcall(vim.json.decode, termdefs_raw)
if not ok then
broadcast_error('E557: Failed to parse $NVIM_TERMDEFS: ' .. vim.inspect(termdefs_or_err))
return
elseif type(termdefs_or_err) ~= 'table' or vim.isarray(termdefs_or_err) then
broadcast_error('E557: expected $NVIM_TERMDEFS to be table. :help $NVIM_TERMDEFS')
return
end
return termdefs_or_err
end
end
return M