summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-05-16 14:30:18 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-05-16 14:30:18 +0000
commit0682413dd3d0694d87cccec9da4f07ebf9c639fd (patch)
tree6604b9248af5a157a0d6ca6b70390ae1d0c4e740 /usr.bin/tmux
parent642e36e7054bb7c9c2ec8995fcfc1e9cd177631c (diff)
Move terminal features into a single file.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/format.c4
-rw-r--r--usr.bin/tmux/server-client.c4
-rw-r--r--usr.bin/tmux/tmux.15
-rw-r--r--usr.bin/tmux/tmux.h4
-rw-r--r--usr.bin/tmux/tty-features.c40
-rw-r--r--usr.bin/tmux/tty-keys.c57
6 files changed, 66 insertions, 48 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index ac561eaa843..015d0638937 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.248 2020/05/16 14:10:29 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.249 2020/05/16 14:30:17 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2624,6 +2624,8 @@ format_defaults_client(struct format_tree *ft, struct client *c)
format_add(ft, "client_termname", "%s", c->term_name);
format_add(ft, "client_termfeatures", "%s",
tty_get_features(c->term_features));
+ if (c->term_type != NULL)
+ format_add(ft, "client_termtype", "%s", c->term_type);
format_add_tv(ft, "client_created", &c->creation_time);
format_add_tv(ft, "client_activity", &c->activity_time);
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index ed22da9a333..895aad8cbf7 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.332 2020/04/21 06:34:13 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.333 2020/05/16 14:30:17 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -296,7 +296,9 @@ server_client_lost(struct client *c)
if (c->flags & CLIENT_TERMINAL)
tty_free(&c->tty);
free(c->ttyname);
+
free(c->term_name);
+ free(c->term_type);
status_free(c);
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 064ef3f95bf..c35d05cc47b 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.753 2020/05/16 14:22:51 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.754 2020/05/16 14:30:17 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -4463,7 +4463,8 @@ 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_termfeatures" Ta "" Ta "Terminal features of client"
+.It Li "client_termtype" Ta "" Ta "Terminal type of client, if available"
+.It Li "client_termfeatures" Ta "" Ta "Terminal features of client, if any"
.It Li "client_tty" Ta "" Ta "Pseudo terminal of client"
.It Li "client_utf8" Ta "" Ta "1 if client supports UTF-8"
.It Li "client_width" Ta "" Ta "Width of client"
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 5968ede237d..dd8dea36bef 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1018 2020/05/16 14:26:33 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1019 2020/05/16 14:30:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1504,6 +1504,7 @@ struct client {
char *term_name;
int term_features;
+ char *term_type;
char *ttyname;
struct tty tty;
@@ -2028,6 +2029,7 @@ const char *tty_term_describe(struct tty_term *, enum tty_code_code);
void tty_add_features(int *, const char *, const char *);
const char *tty_get_features(int);
int tty_apply_features(struct tty_term *, int);
+void tty_default_features(int *, const char *, u_int);
/* tty-acs.c */
int tty_acs_needed(struct tty *);
diff --git a/usr.bin/tmux/tty-features.c b/usr.bin/tmux/tty-features.c
index d6c6b747360..8b5687c754f 100644
--- a/usr.bin/tmux/tty-features.c
+++ b/usr.bin/tmux/tty-features.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty-features.c,v 1.8 2020/05/16 14:26:33 nicm Exp $ */
+/* $OpenBSD: tty-features.c,v 1.9 2020/05/16 14:30:17 nicm Exp $ */
/*
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -201,7 +201,7 @@ tty_add_features(int *feat, const char *s, const char *separators)
char *next, *loop, *copy;
u_int i;
- log_debug("%s: %s", __func__, s);
+ log_debug("adding terminal features %s", s);
loop = copy = xstrdup(s);
while ((next = strsep(&loop, separators)) != NULL) {
@@ -275,3 +275,39 @@ tty_apply_features(struct tty_term *term, int feat)
term->features |= feat;
return (1);
}
+
+void
+tty_default_features(int *feat, const char *name, u_int version)
+{
+ static struct {
+ const char *name;
+ u_int version;
+ const char *features;
+ } table[] = {
+ { .name = "mintty",
+ .features = "256,RGB,ccolour,clipboard,cstyle,margins,overline,title"
+ },
+ { .name = "tmux",
+ .features = "256,RGB,ccolour,clipboard,cstyle,overline,title,usstyle"
+ },
+ { .name = "rxvt-unicode",
+ .features = "256,title"
+ },
+ { .name = "iTerm2",
+ .features = "256,RGB,clipboard,cstyle,margins,sync,title"
+ },
+ { .name = "XTerm",
+ .features = "256,RGB,ccolour,clipboard,cstyle,margins,rectfill,title"
+ }
+ };
+ u_int i;
+
+ for (i = 0; i < nitems(table); i++) {
+ if (strcmp(table[i].name, name) != 0)
+ continue;
+ if (version != 0 && version < table[i].version)
+ continue;
+ tty_add_features(feat, table[i].features, ",");
+ }
+
+}
diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c
index 10ee4ad7627..9a8ab2c7b25 100644
--- a/usr.bin/tmux/tty-keys.c
+++ b/usr.bin/tmux/tty-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty-keys.c,v 1.129 2020/05/16 14:18:39 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.130 2020/05/16 14:30:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1070,28 +1070,13 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
",");
break;
case 'M': /* mintty */
- tty_add_features(&c->term_features,
- "256,"
- "RGB,"
- "title",
- ",");
+ tty_default_features(&c->term_features, "mintty", 0);
break;
case 'T': /* tmux */
- tty_add_features(&c->term_features,
- "256,"
- "RGB,"
- "ccolour,"
- "cstyle,"
- "overline,"
- "title,"
- "usstyle",
- ",");
+ tty_default_features(&c->term_features, "tmux", 0);
break;
case 'U': /* rxvt-unicode */
- tty_add_features(&c->term_features,
- "256,"
- "title",
- ",");
+ tty_default_features(&c->term_features, "rxvt-unicode", 0);
break;
}
log_debug("%s: received secondary DA %.*s", c->name, (int)*size, buf);
@@ -1112,7 +1097,7 @@ tty_keys_extended_device_attributes(struct tty *tty, const char *buf,
{
struct client *c = tty->client;
u_int i;
- char tmp[64];
+ char tmp[128];
*size = 0;
if (tty->flags & TTY_HAVEXDA)
@@ -1150,29 +1135,19 @@ tty_keys_extended_device_attributes(struct tty *tty, const char *buf,
*size = 5 + i;
/* Add terminal features. */
- if (strncmp(tmp, "iTerm2 ", 7) == 0) {
- tty_add_features(&c->term_features,
- "256,"
- "RGB,"
- "clipboard,"
- "cstyle,"
- "margins,"
- "sync,"
- "title",
- ",");
- } else if (strncmp(tmp, "tmux ", 5) == 0) {
- tty_add_features(&c->term_features,
- "256,"
- "RGB,"
- "ccolour,"
- "cstyle,"
- "overline,"
- "title,"
- "usstyle",
- ",");
- }
+ if (strncmp(tmp, "iTerm2 ", 7) == 0)
+ tty_default_features(&c->term_features, "iTerm2", 0);
+ else if (strncmp(tmp, "tmux ", 5) == 0)
+ tty_default_features(&c->term_features, "tmux", 0);
+ else if (strncmp(tmp, "XTerm(", 6) == 0)
+ tty_default_features(&c->term_features, "xterm", 0);
+ else if (strncmp(tmp, "mintty ", 7) == 0)
+ tty_default_features(&c->term_features, "mintty", 0);
log_debug("%s: received extended DA %.*s", c->name, (int)*size, buf);
+ free(c->term_type);
+ c->term_type = xstrdup(tmp);
+
tty_update_features(tty);
tty->flags |= TTY_HAVEXDA;