Use the tsl and fsl terminfo(5) capabilities to update terminal title

and automatically fill them in on terminals with the XT capability
(which means their title setting is xterm-compatible). From hsim at
gmx.li.
This commit is contained in:
Nicholas Marriott 2011-05-08 19:53:06 +00:00
parent b0a88ebead
commit 295ace6820
5 changed files with 28 additions and 11 deletions

View File

@ -355,7 +355,7 @@ const struct options_table_entry session_options_table[] = {
{ .name = "terminal-overrides", { .name = "terminal-overrides",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.default_str = "*88col*:colors=88,*256col*:colors=256" .default_str = "*88col*:colors=88,*256col*:colors=256,xterm*:XT"
}, },
{ .name = "update-environment", { .name = "update-environment",

2
tmux.1
View File

@ -2145,7 +2145,7 @@ The default value forcibly corrects the
.Ql colors .Ql colors
entry for terminals which support 88 or 256 colours: entry for terminals which support 88 or 256 colours:
.Bd -literal -offset indent .Bd -literal -offset indent
"*88col*:colors=88,*256col*:colors=256" "*88col*:colors=88,*256col*:colors=256,xterm*:XT"
.Ed .Ed
.It Ic update-environment Ar variables .It Ic update-environment Ar variables
Set a space-separated string containing a list of environment variables to be Set a space-separated string containing a list of environment variables to be

7
tmux.h
View File

@ -205,6 +205,7 @@ enum tty_code_code {
TTYC_EL, /* clr_eol, ce */ TTYC_EL, /* clr_eol, ce */
TTYC_EL1, /* clr_bol, cb */ TTYC_EL1, /* clr_bol, cb */
TTYC_ENACS, /* ena_acs, eA */ TTYC_ENACS, /* ena_acs, eA */
TTYC_FSL, /* from_status_line, fsl */
TTYC_HOME, /* cursor_home, ho */ TTYC_HOME, /* cursor_home, ho */
TTYC_HPA, /* column_address, ch */ TTYC_HPA, /* column_address, ch */
TTYC_ICH, /* parm_ich, IC */ TTYC_ICH, /* parm_ich, IC */
@ -317,17 +318,19 @@ enum tty_code_code {
TTYC_SETAB, /* set_a_background, AB */ TTYC_SETAB, /* set_a_background, AB */
TTYC_SETAF, /* set_a_foreground, AF */ TTYC_SETAF, /* set_a_foreground, AF */
TTYC_SGR0, /* exit_attribute_mode, me */ TTYC_SGR0, /* exit_attribute_mode, me */
TTYC_SITM, /* enter_italics_mode, it */
TTYC_SMACS, /* enter_alt_charset_mode, as */ TTYC_SMACS, /* enter_alt_charset_mode, as */
TTYC_SMCUP, /* enter_ca_mode, ti */ TTYC_SMCUP, /* enter_ca_mode, ti */
TTYC_SMIR, /* enter_insert_mode, im */ TTYC_SMIR, /* enter_insert_mode, im */
TTYC_SMKX, /* keypad_xmit, ks */ TTYC_SMKX, /* keypad_xmit, ks */
TTYC_SMSO, /* enter_standout_mode, so */ TTYC_SMSO, /* enter_standout_mode, so */
TTYC_SMUL, /* enter_underline_mode, us */ TTYC_SMUL, /* enter_underline_mode, us */
TTYC_SITM, /* enter_italics_mode, it */ TTYC_TSL, /* to_status_line, tsl */
TTYC_VPA, /* row_address, cv */ TTYC_VPA, /* row_address, cv */
TTYC_XENL, /* eat_newline_glitch, xn */ TTYC_XENL, /* eat_newline_glitch, xn */
TTYC_XT, /* xterm(1)-compatible title, XT */
}; };
#define NTTYCODE (TTYC_XENL + 1) #define NTTYCODE (TTYC_XT + 1)
/* Termcap types. */ /* Termcap types. */
enum tty_code_type { enum tty_code_type {

View File

@ -60,6 +60,7 @@ const struct tty_term_code_entry tty_term_codes[NTTYCODE] = {
{ TTYC_EL, TTYCODE_STRING, "el" }, { TTYC_EL, TTYCODE_STRING, "el" },
{ TTYC_EL1, TTYCODE_STRING, "el1" }, { TTYC_EL1, TTYCODE_STRING, "el1" },
{ TTYC_ENACS, TTYCODE_STRING, "enacs" }, { TTYC_ENACS, TTYCODE_STRING, "enacs" },
{ TTYC_FSL, TTYCODE_STRING, "fsl" },
{ TTYC_HOME, TTYCODE_STRING, "home" }, { TTYC_HOME, TTYCODE_STRING, "home" },
{ TTYC_HPA, TTYCODE_STRING, "hpa" }, { TTYC_HPA, TTYCODE_STRING, "hpa" },
{ TTYC_ICH, TTYCODE_STRING, "ich" }, { TTYC_ICH, TTYCODE_STRING, "ich" },
@ -172,15 +173,17 @@ const struct tty_term_code_entry tty_term_codes[NTTYCODE] = {
{ TTYC_SETAB, TTYCODE_STRING, "setab" }, { TTYC_SETAB, TTYCODE_STRING, "setab" },
{ TTYC_SETAF, TTYCODE_STRING, "setaf" }, { TTYC_SETAF, TTYCODE_STRING, "setaf" },
{ TTYC_SGR0, TTYCODE_STRING, "sgr0" }, { TTYC_SGR0, TTYCODE_STRING, "sgr0" },
{ TTYC_SITM, TTYCODE_STRING, "sitm" },
{ TTYC_SMACS, TTYCODE_STRING, "smacs" }, { TTYC_SMACS, TTYCODE_STRING, "smacs" },
{ TTYC_SMCUP, TTYCODE_STRING, "smcup" }, { TTYC_SMCUP, TTYCODE_STRING, "smcup" },
{ TTYC_SMIR, TTYCODE_STRING, "smir" }, { TTYC_SMIR, TTYCODE_STRING, "smir" },
{ TTYC_SMKX, TTYCODE_STRING, "smkx" }, { TTYC_SMKX, TTYCODE_STRING, "smkx" },
{ TTYC_SMSO, TTYCODE_STRING, "smso" }, { TTYC_SMSO, TTYCODE_STRING, "smso" },
{ TTYC_SMUL, TTYCODE_STRING, "smul" }, { TTYC_SMUL, TTYCODE_STRING, "smul" },
{ TTYC_SITM, TTYCODE_STRING, "sitm" }, { TTYC_TSL, TTYCODE_STRING, "tsl" },
{ TTYC_VPA, TTYCODE_STRING, "vpa" }, { TTYC_VPA, TTYCODE_STRING, "vpa" },
{ TTYC_XENL, TTYCODE_FLAG, "xenl" }, { TTYC_XENL, TTYCODE_FLAG, "xenl" },
{ TTYC_XT, TTYCODE_FLAG, "XT" },
}; };
char * char *
@ -252,7 +255,7 @@ tty_term_override(struct tty_term *term, const char *overrides)
entstr[strlen(entstr) - 1] = '\0'; entstr[strlen(entstr) - 1] = '\0';
removeflag = 1; removeflag = 1;
} else } else
continue; val = xstrdup("");
for (i = 0; i < NTTYCODE; i++) { for (i = 0; i < NTTYCODE; i++) {
ent = &tty_term_codes[i]; ent = &tty_term_codes[i];
@ -423,6 +426,18 @@ tty_term_find(char *name, int fd, const char *overrides, char **cause)
for (; acs[0] != '\0' && acs[1] != '\0'; acs += 2) for (; acs[0] != '\0' && acs[1] != '\0'; acs += 2)
term->acs[(u_char) acs[0]][0] = acs[1]; term->acs[(u_char) acs[0]][0] = acs[1];
/* On terminals with xterm titles (XT), fill in tsl and fsl. */
if (tty_term_flag(term, TTYC_XT) &&
!tty_term_has(term, TTYC_TSL) &&
!tty_term_has(term, TTYC_FSL)) {
code = &term->codes[TTYC_TSL];
code->value.string = xstrdup("\033]0;");
code->type = TTYCODE_STRING;
code = &term->codes[TTYC_FSL];
code->value.string = xstrdup("\007");
code->type = TTYCODE_STRING;
}
return (term); return (term);
error: error:

9
tty.c
View File

@ -369,14 +369,13 @@ tty_pututf8(struct tty *tty, const struct grid_utf8 *gu)
void void
tty_set_title(struct tty *tty, const char *title) tty_set_title(struct tty *tty, const char *title)
{ {
if (strstr(tty->termname, "xterm") == NULL && if (!tty_term_has(tty->term, TTYC_TSL) ||
strstr(tty->termname, "rxvt") == NULL && !tty_term_has(tty->term, TTYC_FSL))
strcmp(tty->termname, "screen") != 0)
return; return;
tty_puts(tty, "\033]0;"); tty_putcode(tty, TTYC_TSL);
tty_puts(tty, title); tty_puts(tty, title);
tty_putc(tty, '\007'); tty_putcode(tty, TTYC_FSL);
} }
void void