=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty-term.c,v retrieving revision 1.72 retrieving revision 1.73 diff -c -r1.72 -r1.73 *** src/usr.bin/tmux/tty-term.c 2020/04/16 13:35:24 1.72 --- src/usr.bin/tmux/tty-term.c 2020/04/20 13:25:36 1.73 *************** *** 1,4 **** ! /* $OpenBSD: tty-term.c,v 1.72 2020/04/16 13:35:24 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: tty-term.c,v 1.73 2020/04/20 13:25:36 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 27,33 **** #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); --- 27,32 ---- *************** *** 335,356 **** return (value); } ! static void ! tty_term_override(struct tty_term *term, const char *override) { const struct tty_term_code_entry *ent; struct tty_code *code; size_t offset = 0; char *cp, *value, *s; ! const char *errstr; 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) { if (*s == '\0') continue; value = NULL; --- 334,351 ---- return (value); } ! 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, *name = term->name; u_int i; int n, remove; ! while ((s = tty_term_override_next(capabilities, &offset)) != NULL) { if (*s == '\0') continue; value = NULL; *************** *** 369,380 **** } 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); for (i = 0; i < tty_term_ncodes(); i++) { ent = &tty_term_codes[i]; --- 364,377 ---- } else value = xstrdup(""); ! 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]; *************** *** 414,420 **** } struct tty_term * ! tty_term_find(char *name, int fd, char **cause) { struct tty_term *term; const struct tty_term_code_entry *ent; --- 411,417 ---- } struct tty_term * ! 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; *************** *** 425,443 **** u_int i; int n, error; const char *s, *acs; ! LIST_FOREACH(term, &tty_terms, entry) { ! if (strcmp(term->name, name) == 0) { ! term->references++; ! return (term); ! } ! } ! log_debug("new term: %s", name); ! term = xmalloc(sizeof *term); 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); --- 422,435 ---- u_int i; int n, error; const char *s, *acs; + size_t offset; + char *first; ! log_debug("adding term %s", name); ! term = xcalloc(1, sizeof *term); ! term->tty = tty; term->name = xstrdup(name); term->codes = xcalloc(tty_term_ncodes(), sizeof *term->codes); LIST_INSERT_HEAD(&tty_terms, term, entry); *************** *** 495,506 **** } } /* 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); a = options_array_next(a); } --- 487,517 ---- } } + /* 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); ! 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); } *************** *** 523,541 **** goto error; } ! /* Set flag if terminal has 256 colours. */ ! if (tty_term_number(term, TTYC_COLORS) >= 256) ! term->flags |= TERM_256COLOURS; ! /* 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; ! /* Set flag if terminal has synchronized updates. */ ! if (tty_term_flag(term, TTYC_SYNC)) ! term->flags |= TERM_SYNC; /* * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1 --- 534,551 ---- goto error; } ! /* 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", ":,"); ! /* Add feature if terminal has XT. */ ! if (tty_term_flag(term, TTYC_XT)) ! tty_add_features(feat, "title", ":,"); ! /* Apply the features. */ ! tty_apply_features(term, *feat); /* * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1 *************** *** 559,576 **** 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)); --- 569,574 ---- *************** *** 587,603 **** { u_int i; ! if (--term->references != 0) ! return; - LIST_REMOVE(term, entry); - for (i = 0; i < tty_term_ncodes(); i++) { if (term->codes[i].type == TTYCODE_STRING) free(term->codes[i].value.string); } free(term->codes); free(term->name); free(term); } --- 585,599 ---- { u_int i; ! log_debug("removing term %s", term->name); for (i = 0; i < tty_term_ncodes(); i++) { if (term->codes[i].type == TTYCODE_STRING) free(term->codes[i].value.string); } free(term->codes); + LIST_REMOVE(term, entry); free(term->name); free(term); }