From 64135ae365b55d207bc071738f0a90b71becb435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 21 Jul 2019 17:48:06 +0200 Subject: [PATCH] csi: implement CSI 22t and CSI 23t 22;0|1|2t pushes the current window title/icon to the stack, while 23 pops it. The second parameter, 0|1|2 has the following meaning: 0 - push/pop icon+title 1 - push/pop icon 2 - push/pop title --- csi.c | 36 ++++++++++++++++++++++++++++++++---- foot.info | 4 ++-- main.c | 3 +++ terminal.h | 1 + 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/csi.c b/csi.c index 3fcda546..067ecf4a 100644 --- a/csi.c +++ b/csi.c @@ -546,11 +546,39 @@ csi_dispatch(struct terminal *term, uint8_t final) break; } - case 't': - /* 22 - save window title */ - /* 23 - restore window title */ - LOG_WARN("ignoring %s", csi_as_string(term, final)); + case 't': { + unsigned param = vt_param_get(term, 0, 0); + + switch (param) { + case 22: { /* push window title */ + /* 0 - icon + title, 1 - icon, 2 - title */ + unsigned what = vt_param_get(term, 1, 0); + if (what == 0 || what == 2) { + tll_push_back( + term->window_title_stack, strdup(term->window_title)); + } + break; + } + + case 23: { /* pop window title */ + /* 0 - icon + title, 1 - icon, 2 - title */ + unsigned what = vt_param_get(term, 1, 0); + if (what == 0 || what == 2) { + if (tll_length(term->window_title_stack) > 0) { + char *title = tll_pop_back(term->window_title_stack); + term_set_window_title(term, title); + free(title); + } + } + break; + } + + default: + LOG_WARN("ignoring %s", csi_as_string(term, final)); + break; + } break; + } case 'n': { if (term->vt.params.idx > 0) { diff --git a/foot.info b/foot.info index c0f371ab..aeb8e044 100644 --- a/foot.info +++ b/foot.info @@ -156,7 +156,7 @@ foot+base|foot base fragment, ritm=\E[23m, rmacs=\E(B, rmam=\E[?7l, - rmcup=\E[?1049l, + rmcup=\E[?1049l\E[23;0t, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[27m, @@ -169,7 +169,7 @@ foot+base|foot base fragment, sitm=\E[3m, smacs=\E(0, smam=\E[?7h, - smcup=\E[?1049h, + smcup=\E[?1049h\E[22;0t, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m, diff --git a/main.c b/main.c index f2d03171..2ec17618 100644 --- a/main.c +++ b/main.c @@ -324,6 +324,7 @@ main(int argc, char *const *argv) .cursor_keys_mode = CURSOR_KEYS_NORMAL, .keypad_keys_mode = KEYPAD_NUMERICAL, .auto_margin = true, + .window_title_stack = tll_init(), .vt = { .state = 1, /* STATE_GROUND */ .attrs = { @@ -848,7 +849,9 @@ out: for (int row = 0; row < term.alt.num_rows; row++) grid_row_free(term.alt.rows[row]); free(term.alt.rows); + free(term.window_title); + tll_free_and_free(term.window_title_stack, free); for (size_t i = 0; i < sizeof(term.fonts) / sizeof(term.fonts[0]); i++) { struct font *f = &term.fonts[i]; diff --git a/terminal.h b/terminal.h index fd924b42..a6cf65cd 100644 --- a/terminal.h +++ b/terminal.h @@ -246,6 +246,7 @@ struct terminal { int selected_charset; enum charset charset[4]; /* G0-G3 */ char *window_title; + tll(char *) window_title_stack; struct vt vt; struct kbd kbd;