diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-03 14:10:55 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-03 14:10:55 +0000 |
commit | c787f334c094f169da9a551d38aaeeb1ea5d2d31 (patch) | |
tree | 1ae7ac4acba998f72e99ac9759c488bd50125479 /usr.bin/tmux | |
parent | 6f933eab8289d6d1f5f910e1af06e75b92a70bea (diff) |
Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.
Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-attach-session.c | 8 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-session.c | 8 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-set-option.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-string.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 42 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 6 | ||||
-rw-r--r-- | usr.bin/tmux/tty-term.c | 101 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 7 |
9 files changed, 147 insertions, 39 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index 22d6423b891..08aec80bec7 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.6 2009/07/26 12:58:44 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.7 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -43,7 +43,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) struct cmd_target_data *data = self->data; struct session *s; struct client *c; - char *cause; + char *overrides, *cause; u_int i; if (ARRAY_LENGTH(&sessions) == 0) { @@ -80,7 +80,9 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) return (-1); } - if (tty_open(&ctx->cmdclient->tty, &cause) != 0) { + overrides = + options_get_string(&s->options, "terminal-overrides"); + if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) { ctx->error(ctx, "terminal open failed: %s", cause); xfree(cause); return (-1); diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index a5ea55a3329..38f9038b9d8 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.8 2009/07/26 12:58:44 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.9 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -108,7 +108,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_new_session_data *data = self->data; struct session *s; - char *cmd, *cwd, *cause; + char *overrides, *cmd, *cwd, *cause; int detached; u_int sx, sy; @@ -147,7 +147,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) return (-1); } - if (tty_open(&ctx->cmdclient->tty, &cause) != 0) { + overrides = + options_get_string(&global_s_options, "terminal-overrides"); + if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) { ctx->error(ctx, "open terminal failed: %s", cause); xfree(cause); return (-1); diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 1a98c35382d..8f1d1c792b6 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.9 2009/07/26 12:58:44 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.10 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -77,7 +77,8 @@ const struct set_option_entry set_option_table[] = { { "status-left-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, { "status-right", SET_OPTION_STRING, 0, 0, NULL }, { "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, - { "status-utf8", SET_OPTION_FLAG, 0, 0, NULL }, + { "status-utf8", SET_OPTION_FLAG, 0, 0, NULL }, + { "terminal-overrides", SET_OPTION_STRING, 0, 0, NULL }, { "visual-activity", SET_OPTION_FLAG, 0, 0, NULL }, { "visual-bell", SET_OPTION_FLAG, 0, 0, NULL }, { "visual-content", SET_OPTION_FLAG, 0, 0, NULL }, diff --git a/usr.bin/tmux/cmd-string.c b/usr.bin/tmux/cmd-string.c index 1c1435f5956..2094d35b9c6 100644 --- a/usr.bin/tmux/cmd-string.c +++ b/usr.bin/tmux/cmd-string.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-string.c,v 1.4 2009/07/13 18:49:36 nicm Exp $ */ +/* $OpenBSD: cmd-string.c,v 1.5 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -215,6 +215,9 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc) switch (ch = cmd_string_getc(s, p)) { case EOF: goto error; + case 'e': + ch = '\033'; + break; case 'r': ch = '\r'; break; diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 565ecad28ef..1b4d69a2660 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.53 2009/07/30 16:59:24 jmc Exp $ +.\" $OpenBSD: tmux.1,v 1.54 2009/08/03 14:10:54 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: July 30 2009 $ +.Dd $Mdocdate: August 3 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -1418,6 +1418,44 @@ and .Ic status-right strings as UTF-8; notably, this is important for wide characters. This option defaults to off. +.It Xo Ic terminal-overrides +.Ar string +.Xc +Contains a list of entries which override terminal descriptions read using +.Xr terminfo 5 . +.Ar string +is a comma-separated list of items each a colon-separated string made up of a +terminal type pattern (matched using +.Xr fnmatch 3 ) +and a set of +.Em name=value +entries. +.Pp +For example, to set the +.Ql clear +.Xr terminfo 5 +entry to +.Ql \ee[H\ee[2J +for all terminal types and the +.Ql dch1 +entry to +.Ql \ee[P +for the +.Ql rxvt +terminal type, the option could be set to the string: +.Bd -literal -offset indent +"*:clear=\ee[H\ee[2J,rxvt:dch1=\ee[P" +.Ed +.Pp +The terminal entry value is passed through +.Xr strunvis 3 +before interpretation. +The default value forcibly corrects the +.Ql colors +entry for terminals which support 88 or 256 colours: +.Bd -literal -offset indent +"*88col*:colors=88,*256col*:colors=256" +.Ed .It Xo Ic visual-activity .Op Ic on | Ic off .Xc diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 8ff1d6d089a..2054309155d 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.24 2009/07/30 07:04:50 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.25 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -367,6 +367,8 @@ main(int argc, char **argv) options_set_number(&global_s_options, "status-utf8", 1); else options_set_number(&global_s_options, "status-utf8", 0); + options_set_string(&global_s_options, + "terminal-overrides", "*88col*:colors=88,*256col*:colors=256"); options_set_number(&global_s_options, "visual-activity", 0); options_set_number(&global_s_options, "visual-bell", 0); options_set_number(&global_s_options, "visual-content", 0); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index eecb88fa4d5..90e117de049 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.66 2009/07/30 16:32:12 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.67 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1130,7 +1130,7 @@ void tty_detect_utf8(struct tty *); void tty_set_title(struct tty *, const char *); void tty_update_mode(struct tty *, int); void tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int); -int tty_open(struct tty *, char **); +int tty_open(struct tty *, const char *, char **); void tty_close(struct tty *, int); void tty_free(struct tty *, int); void tty_write(void (*)(struct tty *, struct tty_ctx *), struct tty_ctx *); @@ -1153,7 +1153,7 @@ void tty_cmd_reverseindex(struct tty *, struct tty_ctx *); /* tty-term.c */ extern struct tty_terms tty_terms; extern struct tty_term_code_entry tty_term_codes[NTTYCODE]; -struct tty_term *tty_term_find(char *, int, char **); +struct tty_term *tty_term_find(char *, int, const char *, char **); void tty_term_free(struct tty_term *); int tty_term_has(struct tty_term *, enum tty_code_code); const char *tty_term_string(struct tty_term *, enum tty_code_code); diff --git a/usr.bin/tmux/tty-term.c b/usr.bin/tmux/tty-term.c index d7dcf4fea4e..2fa78639020 100644 --- a/usr.bin/tmux/tty-term.c +++ b/usr.bin/tmux/tty-term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-term.c,v 1.4 2009/08/02 20:47:35 matthieu Exp $ */ +/* $OpenBSD: tty-term.c,v 1.5 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -19,12 +19,15 @@ #include <sys/types.h> #include <curses.h> +#include <fnmatch.h> +#include <stdlib.h> #include <string.h> #include <term.h> +#include <vis.h> #include "tmux.h" -void tty_term_quirks(struct tty_term *); +void tty_term_override(struct tty_term *, const char *); char *tty_term_strip(const char *); struct tty_terms tty_terms = SLIST_HEAD_INITIALIZER(tty_terms); @@ -140,27 +143,87 @@ tty_term_strip(const char *s) } void -tty_term_quirks(struct tty_term *term) +tty_term_override(struct tty_term *term, const char *overrides) { - if (strncmp(term->name, "rxvt", 4) == 0) { - /* rxvt supports dch1 but some termcap files do not have it. */ - if (!tty_term_has(term, TTYC_DCH1)) { - term->codes[TTYC_DCH1].type = TTYCODE_STRING; - term->codes[TTYC_DCH1].value.string = xstrdup("\033[P"); + struct tty_term_code_entry *ent; + struct tty_code *code; + char *termnext, *termstr, *entnext, *entstr; + char *s, *ptr, *val; + const char *errstr; + u_int i; + int n, removeflag; + + s = xstrdup(overrides); + + termnext = s; + while ((termstr = strsep(&termnext, ",")) != NULL) { + entnext = termstr; + + entstr = strsep(&entnext, ":"); + if (entstr == NULL || entnext == NULL) + continue; + if (fnmatch(entstr, term->name, 0) != 0) + continue; + while ((entstr = strsep(&entnext, ":")) != NULL) { + if (*entstr == '\0') + continue; + + val = NULL; + removeflag = 0; + if ((ptr = strchr(entstr, '=')) != NULL) { + *ptr++ = '\0'; + val = xstrdup(ptr); + if (strunvis(val, ptr) == NULL) { + xfree(val); + val = xstrdup(ptr); + } + } else if (entstr[strlen(entstr) - 1] == '@') { + entstr[strlen(entstr) - 1] = '\0'; + removeflag = 1; + } + + for (i = 0; i < NTTYCODE; i++) { + ent = &tty_term_codes[i]; + if (strcmp(entstr, ent->name) != 0) + continue; + code = &term->codes[ent->code]; + + if (removeflag) { + code->type = TTYCODE_NONE; + continue; + } + switch (ent->type) { + case TTYCODE_NONE: + break; + case TTYCODE_STRING: + xfree(code->value.string); + code->value.string = xstrdup(val); + code->type = ent->type; + break; + case TTYCODE_NUMBER: + n = strtonum(val, 0, INT_MAX, &errstr); + if (errstr != NULL) + break; + code->value.number = n; + code->type = ent->type; + break; + case TTYCODE_FLAG: + code->value.flag = 1; + code->type = ent->type; + break; + } + } + + if (val != NULL) + xfree(val); } } - if (strncmp(term->name, "xterm", 5) == 0) { - /* xterm supports ich1 but some termcaps omit it. */ - if (!tty_term_has(term, TTYC_ICH1)) { - term->codes[TTYC_ICH1].type = TTYCODE_STRING; - term->codes[TTYC_ICH1].value.string = xstrdup("\033[@"); - } - } + xfree(s); } struct tty_term * -tty_term_find(char *name, int fd, char **cause) +tty_term_find(char *name, int fd, const char *overrides, char **cause) { struct tty_term *term; struct tty_term_code_entry *ent; @@ -235,7 +298,7 @@ tty_term_find(char *name, int fd, char **cause) break; } } - tty_term_quirks(term); + tty_term_override(term, overrides); /* Delete curses data. */ del_curterm(cur_term); @@ -297,12 +360,8 @@ tty_term_find(char *name, int fd, char **cause) */ if (tty_term_number(term, TTYC_COLORS) == 256) term->flags |= TERM_256COLOURS; - if (strstr(name, "256col") != NULL) /* XXX HACK */ - term->flags |= TERM_256COLOURS; if (tty_term_number(term, TTYC_COLORS) == 88) term->flags |= TERM_88COLOURS; - if (strstr(name, "88col") != NULL) /* XXX HACK */ - term->flags |= TERM_88COLOURS; /* * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1 diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index e7678a89e70..270b9bae2e5 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.16 2009/07/27 11:33:21 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.17 2009/08/03 14:10:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -57,7 +57,7 @@ tty_init(struct tty *tty, char *path, char *term) } int -tty_open(struct tty *tty, char **cause) +tty_open(struct tty *tty, const char *overrides, char **cause) { int mode; @@ -79,7 +79,8 @@ tty_open(struct tty *tty, char **cause) else tty->log_fd = -1; - if ((tty->term = tty_term_find(tty->termname, tty->fd, cause)) == NULL) + tty->term = tty_term_find(tty->termname, tty->fd, overrides, cause); + if (tty->term == NULL) goto error; tty->in = buffer_create(BUFSIZ); |