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
This commit is contained in:
Daniel Eklöf 2019-07-21 17:48:06 +02:00
parent 97350f6488
commit 64135ae365
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 38 additions and 6 deletions

36
csi.c
View file

@ -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) {

View file

@ -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,

3
main.c
View file

@ -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];

View file

@ -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;