diff options
author | Thomas Adam <thomas@xteddy.org> | 2020-04-20 17:42:29 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2020-04-20 17:42:29 +0100 |
commit | c706aadf52f746b695aed34297ad0a910d74eb1b (patch) | |
tree | 43d08451081e1d8efbc14f784453b4369f0d5821 /tty-term.c | |
parent | 3898d4e7c872a20d9bb22b44fd3449d21281a931 (diff) | |
parent | 135bb1edeeab3faae8001100aa7c173be9aa91e1 (diff) | |
download | rtmux-c706aadf52f746b695aed34297ad0a910d74eb1b.tar.gz rtmux-c706aadf52f746b695aed34297ad0a910d74eb1b.tar.bz2 rtmux-c706aadf52f746b695aed34297ad0a910d74eb1b.zip |
Merge branch 'obsd-master'
Diffstat (limited to 'tty-term.c')
-rw-r--r-- | tty-term.c | 106 |
1 files changed, 51 insertions, 55 deletions
@@ -30,7 +30,6 @@ #include "tmux.h" -static void tty_term_override(struct tty_term *, const char *); static char *tty_term_strip(const char *); struct tty_terms tty_terms = LIST_HEAD_INITIALIZER(tty_terms); @@ -263,7 +262,7 @@ static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_SMUL] = { TTYCODE_STRING, "smul" }, [TTYC_SMXX] = { TTYCODE_STRING, "smxx" }, [TTYC_SS] = { TTYCODE_STRING, "Ss" }, - [TTYC_SYNC] = { TTYCODE_FLAG, "Sync" }, + [TTYC_SYNC] = { TTYCODE_STRING, "Sync" }, [TTYC_TC] = { TTYCODE_FLAG, "Tc" }, [TTYC_TSL] = { TTYCODE_STRING, "tsl" }, [TTYC_U8] = { TTYCODE_NUMBER, "U8" }, @@ -338,22 +337,18 @@ tty_term_override_next(const char *s, size_t *offset) return (value); } -static void -tty_term_override(struct tty_term *term, const char *override) +void +tty_term_apply(struct tty_term *term, const char *capabilities, int quiet) { const struct tty_term_code_entry *ent; struct tty_code *code; size_t offset = 0; char *cp, *value, *s; - const char *errstr; + const char *errstr, *name = term->name; u_int i; int n, remove; - s = tty_term_override_next(override, &offset); - if (s == NULL || fnmatch(s, term->name, 0) != 0) - return; - - while ((s = tty_term_override_next(override, &offset)) != NULL) { + while ((s = tty_term_override_next(capabilities, &offset)) != NULL) { if (*s == '\0') continue; value = NULL; @@ -372,12 +367,14 @@ tty_term_override(struct tty_term *term, const char *override) } else value = xstrdup(""); - if (remove) - log_debug("%s override: %s@", term->name, s); - else if (*value == '\0') - log_debug("%s override: %s", term->name, s); - else - log_debug("%s override: %s=%s", term->name, s, value); + if (!quiet) { + if (remove) + log_debug("%s override: %s@", name, s); + else if (*value == '\0') + log_debug("%s override: %s", name, s); + else + log_debug("%s override: %s=%s", name, s, value); + } for (i = 0; i < tty_term_ncodes(); i++) { ent = &tty_term_codes[i]; @@ -417,7 +414,7 @@ tty_term_override(struct tty_term *term, const char *override) } struct tty_term * -tty_term_find(char *name, int fd, char **cause) +tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) { struct tty_term *term; const struct tty_term_code_entry *ent; @@ -428,19 +425,14 @@ tty_term_find(char *name, int fd, char **cause) u_int i; int n, error; const char *s, *acs; + size_t offset; + char *first; - LIST_FOREACH(term, &tty_terms, entry) { - if (strcmp(term->name, name) == 0) { - term->references++; - return (term); - } - } - log_debug("new term: %s", name); + log_debug("adding term %s", name); - term = xmalloc(sizeof *term); + term = xcalloc(1, sizeof *term); + term->tty = tty; term->name = xstrdup(name); - term->references = 1; - term->flags = 0; term->codes = xcalloc(tty_term_ncodes(), sizeof *term->codes); LIST_INSERT_HEAD(&tty_terms, term, entry); @@ -498,12 +490,31 @@ tty_term_find(char *name, int fd, char **cause) } } + /* Apply terminal features. */ + o = options_get_only(global_options, "terminal-features"); + 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_add_features(feat, s + offset, ":"); + 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); - tty_term_override(term, ov->string); + 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); } @@ -529,19 +540,18 @@ tty_term_find(char *name, int fd, char **cause) goto error; } - /* Set flag if terminal has 256 colours. */ - if (tty_term_number(term, TTYC_COLORS) >= 256) - term->flags |= TERM_256COLOURS; + /* Add RGB feature if terminal has RGB colours. */ + if ((tty_term_flag(term, TTYC_TC) || tty_term_has(term, TTYC_RGB)) && + (!tty_term_has(term, TTYC_SETRGBF) || + !tty_term_has(term, TTYC_SETRGBB))) + tty_add_features(feat, "RGB", ":,"); - /* Set flag if terminal has RGB colours. */ - if ((tty_term_flag(term, TTYC_TC) || tty_term_has(term, TTYC_RGB)) || - (tty_term_has(term, TTYC_SETRGBF) && - tty_term_has(term, TTYC_SETRGBB))) - term->flags |= TERM_RGBCOLOURS; + /* Add feature if terminal has XT. */ + if (tty_term_flag(term, TTYC_XT)) + tty_add_features(feat, "title", ":,"); - /* Set flag if terminal has synchronized updates. */ - if (tty_term_flag(term, TTYC_SYNC)) - term->flags |= TERM_SYNC; + /* Apply the features. */ + tty_apply_features(term, *feat); /* * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1 @@ -565,18 +575,6 @@ tty_term_find(char *name, int fd, char **cause) for (; acs[0] != '\0' && acs[1] != '\0'; acs += 2) 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; - } - /* Log the capabilities. */ for (i = 0; i < tty_term_ncodes(); i++) log_debug("%s%s", name, tty_term_describe(term, i)); @@ -593,10 +591,7 @@ tty_term_free(struct tty_term *term) { u_int i; - if (--term->references != 0) - return; - - LIST_REMOVE(term, entry); + log_debug("removing term %s", term->name); for (i = 0; i < tty_term_ncodes(); i++) { if (term->codes[i].type == TTYCODE_STRING) @@ -604,6 +599,7 @@ tty_term_free(struct tty_term *term) } free(term->codes); + LIST_REMOVE(term, entry); free(term->name); free(term); } |