Add mode 2031 support (automatic dark/light mode).

Co-Author: Nicholas Marriott <nicholas.marriott@gmail.com>
This commit is contained in:
Jonathan Slenders
2024-12-11 21:56:28 +00:00
parent ef68debc8d
commit e536f48d0e
11 changed files with 338 additions and 93 deletions

View File

@@ -59,6 +59,7 @@ static int tty_keys_device_attributes2(struct tty *, const char *, size_t,
size_t *);
static int tty_keys_extended_device_attributes(struct tty *, const char *,
size_t, size_t *);
static void tty_keys_send_theme_updates(struct tty *);
/* A key tree entry. */
struct tty_key {
@@ -213,6 +214,10 @@ static const struct tty_default_key_raw tty_default_raw_keys[] = {
/* Extended keys. */
{ "\033[1;5Z", '\011'|KEYC_CTRL|KEYC_SHIFT },
/* Theme reporting. */
{ "\033[?997;1n", KEYC_REPORT_DARK_THEME },
{ "\033[?997;2n", KEYC_REPORT_LIGHT_THEME },
};
/* Default xterm keys. */
@@ -791,10 +796,12 @@ tty_keys_next(struct tty *tty)
switch (tty_keys_colours(tty, buf, len, &size, &tty->fg, &tty->bg)) {
case 0: /* yes */
key = KEYC_UNKNOWN;
tty_keys_send_theme_updates(tty);
goto complete_key;
case -1: /* no, or not valid */
break;
case 1: /* partial */
tty_keys_send_theme_updates(tty);
goto partial_key;
}
@@ -1679,3 +1686,16 @@ tty_keys_colours(struct tty *tty, const char *buf, size_t len, size_t *size,
return (0);
}
/* Update theme in every pane for client's session. */
static void
tty_keys_send_theme_updates(struct tty *tty)
{
struct window_pane *wp;
struct winlink *wl;
RB_FOREACH(wl, winlinks, &tty->client->session->windows) {
TAILQ_FOREACH(wp, &wl->window->panes, entry)
window_pane_send_theme_update(wp);
}
}