diff options
author | Gregory Anders <greg@gpanders.com> | 2025-01-14 08:18:59 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-14 08:18:59 -0600 |
commit | f1c45fc7a4a595e460cd245172a5767bddeb09e9 (patch) | |
tree | bf9dd2ffe6acea41c7639828fffef9a8393015fe /src/nvim/terminal.c | |
parent | 7eabc8899af8b2fed1472165b74f43965282974f (diff) | |
download | rneovim-f1c45fc7a4a595e460cd245172a5767bddeb09e9.tar.gz rneovim-f1c45fc7a4a595e460cd245172a5767bddeb09e9.tar.bz2 rneovim-f1c45fc7a4a595e460cd245172a5767bddeb09e9.zip |
feat(terminal): support theme update notifications (DEC mode 2031) (#31999)
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r-- | src/nvim/terminal.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index ad343bad67..2ad5ac49ca 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -179,6 +179,8 @@ struct terminal { StringBuilder *send; ///< When there is a pending TermRequest autocommand, block and store input. } pending; + bool theme_updates; ///< Send a theme update notification when 'bg' changes + bool color_set[16]; char *selection_buffer; /// libvterm selection buffer @@ -193,6 +195,7 @@ static VTermScreenCallbacks vterm_screen_callbacks = { .movecursor = term_movecursor, .settermprop = term_settermprop, .bell = term_bell, + .theme = term_theme, .sb_pushline = term_sb_push, // Called before a line goes offscreen. .sb_popline = term_sb_pop, }; @@ -1141,6 +1144,20 @@ bool terminal_running(const Terminal *term) return !term->closed; } +void terminal_notify_theme(Terminal *term, bool dark) + FUNC_ATTR_NONNULL_ALL +{ + if (!term->theme_updates) { + return; + } + + char buf[10]; + ssize_t ret = snprintf(buf, sizeof(buf), "\x1b[997;%cn", dark ? '1' : '2'); + assert(ret > 0); + assert((size_t)ret <= sizeof(buf)); + terminal_send(term, buf, (size_t)ret); +} + static void terminal_focus(const Terminal *term, bool focus) FUNC_ATTR_NONNULL_ALL { @@ -1259,6 +1276,10 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data) invalidate_terminal(term, -1, -1); break; + case VTERM_PROP_THEMEUPDATES: + term->theme_updates = val->boolean; + break; + default: return 0; } @@ -1273,6 +1294,14 @@ static int term_bell(void *data) return 1; } +/// Called when the terminal wants to query the system theme. +static int term_theme(bool *dark, void *data) + FUNC_ATTR_NONNULL_ALL +{ + *dark = (*p_bg == 'd'); + return 1; +} + /// Scrollback push handler: called just before a line goes offscreen (and libvterm will forget it), /// giving us a chance to store it. /// |