From 117ec1b2e603c2692ab564947b099ec79a20150f Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Apr 2020 15:37:32 +0000 Subject: [PATCH] Apply terminal-overrides after terminal detection, it always takes precedence. --- tmux.h | 3 ++- tty-features.c | 7 +++++-- tty-term.c | 41 ++++++++++++++++++++++++++--------------- tty.c | 3 ++- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/tmux.h b/tmux.h index 5d7dbba7..3fe32b50 100644 --- a/tmux.h +++ b/tmux.h @@ -1997,6 +1997,7 @@ void tty_cmd_syncstart(struct tty *, const struct tty_ctx *); extern struct tty_terms tty_terms; u_int tty_term_ncodes(void); void tty_term_apply(struct tty_term *, const char *, int); +void tty_term_apply_overrides(struct tty_term *); struct tty_term *tty_term_create(struct tty *, char *, int *, int, char **); void tty_term_free(struct tty_term *); int tty_term_has(struct tty_term *, enum tty_code_code); @@ -2017,7 +2018,7 @@ const char *tty_term_describe(struct tty_term *, enum tty_code_code); /* tty-features.c */ void tty_add_features(int *, const char *, const char *); const char *tty_get_features(int); -void tty_apply_features(struct tty_term *, int); +int tty_apply_features(struct tty_term *, int); /* tty-acs.c */ int tty_acs_needed(struct tty *); diff --git a/tty-features.c b/tty-features.c index b6934673..3b12b068 100644 --- a/tty-features.c +++ b/tty-features.c @@ -232,7 +232,7 @@ tty_get_features(int feat) return (s); } -void +int tty_apply_features(struct tty_term *term, int feat) { const struct tty_feature *tf; @@ -240,7 +240,7 @@ tty_apply_features(struct tty_term *term, int feat) u_int i; if (feat == 0) - return; + return (0); log_debug("applying terminal features: %s", tty_get_features(feat)); for (i = 0; i < nitems(tty_features); i++) { @@ -259,5 +259,8 @@ tty_apply_features(struct tty_term *term, int feat) } term->flags |= tf->flags; } + if ((term->features | feat) == term->features) + return (0); term->features |= feat; + return (1); } diff --git a/tty-term.c b/tty-term.c index e1b026ea..f4a18b63 100644 --- a/tty-term.c +++ b/tty-term.c @@ -410,6 +410,30 @@ tty_term_apply(struct tty_term *term, const char *capabilities, int quiet) } } +void +tty_term_apply_overrides(struct tty_term *term) +{ + struct options_entry *o; + struct options_array_item *a; + union options_value *ov; + const char *s; + size_t offset; + char *first; + + o = options_get_only(global_options, "terminal-overrides"); + a = options_array_first(o); + while (a != NULL) { + ov = options_array_item_value(a); + s = ov->string; + + offset = 0; + first = tty_term_override_next(s, &offset); + if (first != NULL && fnmatch(first, term->name, 0) == 0) + tty_term_apply(term, s + offset, 0); + a = options_array_next(a); + } +} + struct tty_term * tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) { @@ -501,20 +525,6 @@ tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) a = options_array_next(a); } - /* Apply terminal overrides. */ - o = options_get_only(global_options, "terminal-overrides"); - a = options_array_first(o); - while (a != NULL) { - ov = options_array_item_value(a); - s = ov->string; - - offset = 0; - first = tty_term_override_next(s, &offset); - if (first != NULL && fnmatch(first, term->name, 0) == 0) - tty_term_apply(term, s + offset, 0); - a = options_array_next(a); - } - /* Delete curses data. */ del_curterm(cur_term); @@ -544,8 +554,9 @@ tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) if (tty_term_flag(term, TTYC_XT)) tty_add_features(feat, "title", ":,"); - /* Apply the features. */ + /* Apply the features and overrides. */ tty_apply_features(term, *feat); + tty_term_apply_overrides(term); /* * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1 diff --git a/tty.c b/tty.c index 0214524c..556931da 100644 --- a/tty.c +++ b/tty.c @@ -469,7 +469,8 @@ tty_update_features(struct tty *tty) { struct client *c = tty->client; - tty_apply_features(tty->term, c->term_features); + if (tty_apply_features(tty->term, c->term_features)) + tty_term_apply_overrides(tty->term); if (tty_use_margin(tty)) tty_puts(tty, "\033[?69h"); /* DECLRMM */