summaryrefslogtreecommitdiffstats
path: root/tty-term.c
diff options
context:
space:
mode:
Diffstat (limited to 'tty-term.c')
-rw-r--r--tty-term.c104
1 files changed, 50 insertions, 54 deletions
diff --git a/tty-term.c b/tty-term.c
index d6faa6ff..1c87ac15 100644
--- a/tty-term.c
+++ b/tty-term.c
@@ -27,7 +27,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);
@@ -335,22 +334,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;
@@ -369,12 +364,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];
@@ -414,7 +411,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;
@@ -425,19 +422,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);
@@ -495,12 +487,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);
}
@@ -523,19 +534,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
@@ -559,18 +569,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));
@@ -587,10 +585,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)
@@ -598,6 +593,7 @@ tty_term_free(struct tty_term *term)
}
free(term->codes);
+ LIST_REMOVE(term, entry);
free(term->name);
free(term);
}