diff --git a/format.c b/format.c index 7608533c..cc270bc0 100644 --- a/format.c +++ b/format.c @@ -1139,20 +1139,25 @@ format_defaults_client(struct format_tree *ft, struct client *c) { struct session *s; const char *name; + struct tty *tty = &c->tty; + const char *types[] = TTY_TYPES; if (ft->s == NULL) ft->s = c->session; format_add(ft, "client_pid", "%ld", (long) c->pid); - format_add(ft, "client_height", "%u", c->tty.sy); - format_add(ft, "client_width", "%u", c->tty.sx); - if (c->tty.path != NULL) - format_add(ft, "client_tty", "%s", c->tty.path); - if (c->tty.termname != NULL) - format_add(ft, "client_termname", "%s", c->tty.termname); + format_add(ft, "client_height", "%u", tty->sy); + format_add(ft, "client_width", "%u", tty->sx); + if (tty->path != NULL) + format_add(ft, "client_tty", "%s", tty->path); format_add(ft, "client_control_mode", "%d", !!(c->flags & CLIENT_CONTROL)); + if (tty->term_name != NULL) + format_add(ft, "client_termname", "%s", tty->term_name); + if (tty->term_name != NULL) + format_add(ft, "client_termtype", "%s", types[tty->term_type]); + format_add_tv(ft, "client_created", &c->creation_time); format_add_tv(ft, "client_activity", &c->activity_time); @@ -1163,7 +1168,7 @@ format_defaults_client(struct format_tree *ft, struct client *c) format_add(ft, "client_prefix", "%d", 1); format_add(ft, "client_key_table", "%s", c->keytable->name); - if (c->tty.flags & TTY_UTF8) + if (tty->flags & TTY_UTF8) format_add(ft, "client_utf8", "%d", 1); else format_add(ft, "client_utf8", "%d", 0); diff --git a/tmux.1 b/tmux.1 index 73ce6e46..bb7a8b1e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3516,6 +3516,7 @@ The following variables are available, where appropriate: .It Li "client_readonly" Ta "" Ta "1 if client is readonly" .It Li "client_session" Ta "" Ta "Name of the client's session" .It Li "client_termname" Ta "" Ta "Terminal name of client" +.It Li "client_termtype" Ta "" Ta "Terminal type of client" .It Li "client_tty" Ta "" Ta "Pseudo terminal of client" .It Li "client_utf8" Ta "" Ta "1 if client supports utf8" .It Li "client_width" Ta "" Ta "Width of client" diff --git a/tmux.h b/tmux.h index 148f1963..b109bffd 100644 --- a/tmux.h +++ b/tmux.h @@ -1114,9 +1114,6 @@ struct tty { u_int rleft; u_int rright; - char *termname; - struct tty_term *term; - int fd; struct bufferevent *event; @@ -1133,6 +1130,8 @@ struct tty { #define TTY_FOCUS 0x40 int flags; + struct tty_term *term; + char *term_name; int term_flags; enum { TTY_VT100, @@ -1154,6 +1153,8 @@ struct tty { struct event key_timer; struct tty_key *key_tree; }; +#define TTY_TYPES \ + { "VT100", "VT101", "VT102", "VT220", "VT320", "VT420", "UNKNOWN" } /* TTY command context. */ struct tty_ctx { diff --git a/tty-keys.c b/tty-keys.c index 802bbbdc..f23411ae 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -837,9 +837,10 @@ static int tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, size_t *size) { - u_int i, a, b; - char tmp[64], *endptr; - const char *s; + u_int i, a, b; + char tmp[64], *endptr; + static const char *types[] = TTY_TYPES; + int type; *size = 0; @@ -877,35 +878,29 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, } else a = b = 0; - s = "UNKNOWN"; + type = TTY_UNKNOWN; switch (a) { case 1: - if (b == 2) { - tty_set_type(tty, TTY_VT100); - s = "VT100"; - } else if (b == 0) { - tty_set_type(tty, TTY_VT101); - s = "VT101"; - } + if (b == 2) + type = TTY_VT100; + else if (b == 0) + type = TTY_VT101; break; case 6: - tty_set_type(tty, TTY_VT102); - s = "VT102"; + type = TTY_VT102; break; case 62: - tty_set_type(tty, TTY_VT220); - s = "VT220"; + type = TTY_VT220; break; case 63: - tty_set_type(tty, TTY_VT320); - s = "VT320"; + type = TTY_VT320; break; case 64: - tty_set_type(tty, TTY_VT420); - s = "VT420"; + type = TTY_VT420; break; } - log_debug("received DA %.*s (%s)", (int)*size, buf, s); + tty_set_type(tty, type); + log_debug("received DA %.*s (%s)", (int)*size, buf, types[type]); return (0); } diff --git a/tty.c b/tty.c index 3892df6d..23a74255 100644 --- a/tty.c +++ b/tty.c @@ -105,9 +105,9 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term) memset(tty, 0, sizeof *tty); if (term == NULL || *term == '\0') - tty->termname = xstrdup("unknown"); + tty->term_name = xstrdup("unknown"); else - tty->termname = xstrdup(term); + tty->term_name = xstrdup(term); tty->fd = fd; tty->client = c; @@ -177,7 +177,7 @@ tty_set_size(struct tty *tty, u_int sx, u_int sy) int tty_open(struct tty *tty, char **cause) { - tty->term = tty_term_find(tty->termname, tty->fd, cause); + tty->term = tty_term_find(tty->term_name, tty->fd, cause); if (tty->term == NULL) { tty_close(tty); return (-1); @@ -364,7 +364,7 @@ tty_free(struct tty *tty) free(tty->ccolour); free(tty->path); - free(tty->termname); + free(tty->term_name); } void