aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/news.txt2
-rw-r--r--runtime/doc/vim_diff.txt6
-rw-r--r--runtime/lua/vim/_defaults.lua24
3 files changed, 32 insertions, 0 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index cb70c81191..7743f5981a 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -287,6 +287,8 @@ The following new APIs and features were added.
• Terminal buffers emit a |TermRequest| autocommand event when the child
process emits an OSC or DCS control sequence.
+• Terminal buffers respond to OSC background and foreground requests. |default-autocmds|
+
==============================================================================
CHANGED FEATURES *news-changed*
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 279fdd646f..46550f42b7 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -145,6 +145,12 @@ nvim_terminal:
- BufReadCmd: Treats "term://" buffers as |terminal| buffers. |terminal-start|
- TermClose: A |terminal| buffer started with no arguments (which thus uses
'shell') and which exits with no error is closed automatically.
+- TermRequest: The terminal emulator responds to OSC background and foreground
+ requests, indicating (1) a black background and white foreground when Nvim
+ option 'background' is "dark" or (2) a white background and black foreground
+ when 'background' is "light". While this may not reflect the actual
+ foreground/background color, it permits 'background' to be retained for a
+ nested Nvim instance running in the terminal emulator.
nvim_cmdwin:
- CmdwinEnter: Limits syntax sync to maxlines=1 in the |cmdwin|.
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 64eb638fd7..07850a5a47 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -155,6 +155,30 @@ do
end,
})
+ vim.api.nvim_create_autocmd('TermRequest', {
+ group = nvim_terminal_augroup,
+ desc = 'Respond to OSC foreground/background color requests',
+ callback = function(args)
+ local fg_request = args.data == '\027]10;?'
+ local bg_request = args.data == '\027]11;?'
+ if fg_request or bg_request then
+ -- WARN: This does not return the actual foreground/background color,
+ -- but rather returns:
+ -- - fg=white/bg=black when Nvim option 'background' is 'dark'
+ -- - fg=black/bg=white when Nvim option 'background' is 'light'
+ local red, green, blue = 0, 0, 0
+ local bg_option_dark = vim.o.background == 'dark'
+ if (fg_request and bg_option_dark) or (bg_request and not bg_option_dark) then
+ red, green, blue = 65535, 65535, 65535
+ end
+ local command = fg_request and 10 or 11
+ local data = string.format('\027]%d;rgb:%04x/%04x/%04x\007', command, red, green, blue)
+ local channel = vim.bo[args.buf].channel
+ vim.api.nvim_chan_send(channel, data)
+ end
+ end,
+ })
+
vim.api.nvim_create_autocmd('CmdwinEnter', {
pattern = '[:>]',
desc = 'Limit syntax sync to maxlines=1 in the command window',