mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
2613ba5000
Enable 'termguicolors' automatically when Nvim can detect that truecolor is supported by the host terminal. If $COLORTERM is set to "truecolor" or "24bit", or the terminal's terminfo entry contains capabilities for Tc, RGB, or setrgbf and setrgbb, then we assume that the terminal supports truecolor. Otherwise, the terminal is queried (using both XTGETTCAP and SGR + DECRQSS). If the terminal's response to these queries (if any) indicates that it supports truecolor, then 'termguicolors' is enabled.
41 lines
957 B
Lua
41 lines
957 B
Lua
local tty = vim.iter(vim.api.nvim_list_uis()):any(function(ui)
|
|
return ui.chan == 1 and ui.stdout_tty
|
|
end)
|
|
|
|
if not tty or vim.g.clipboard ~= nil or vim.o.clipboard ~= '' or not os.getenv('SSH_TTY') then
|
|
return
|
|
end
|
|
|
|
require('vim.termcap').query('Ms', function(cap, found, seq)
|
|
if not found then
|
|
return
|
|
end
|
|
|
|
assert(cap == 'Ms')
|
|
|
|
-- Check 'clipboard' and g:clipboard again to avoid a race condition
|
|
if vim.o.clipboard ~= '' or vim.g.clipboard ~= nil then
|
|
return
|
|
end
|
|
|
|
-- If the terminal reports a sequence other than OSC 52 for the Ms capability
|
|
-- then ignore it. We only support OSC 52 (for now)
|
|
if not seq or not seq:match('^\027%]52') then
|
|
return
|
|
end
|
|
|
|
local osc52 = require('vim.ui.clipboard.osc52')
|
|
|
|
vim.g.clipboard = {
|
|
name = 'OSC 52',
|
|
copy = {
|
|
['+'] = osc52.copy('+'),
|
|
['*'] = osc52.copy('*'),
|
|
},
|
|
paste = {
|
|
['+'] = osc52.paste('+'),
|
|
['*'] = osc52.paste('*'),
|
|
},
|
|
}
|
|
end)
|