diff options
author | nicm <nicm> | 2020-05-16 14:46:14 +0000 |
---|---|---|
committer | nicm <nicm> | 2020-05-16 14:46:14 +0000 |
commit | 7dbe623156e7b0e32e10e5e6445b7b7e448cc3a2 (patch) | |
tree | 0ffb9f32bc1d6548d307731d2e05c2dfb728b667 | |
parent | 21a39c997b82b50b0307e836e4f11f9db6a84e55 (diff) | |
download | rtmux-7dbe623156e7b0e32e10e5e6445b7b7e448cc3a2.tar.gz rtmux-7dbe623156e7b0e32e10e5e6445b7b7e448cc3a2.tar.bz2 rtmux-7dbe623156e7b0e32e10e5e6445b7b7e448cc3a2.zip |
Instead of having a default set of terminals in terminal-overrides that
get XT added and using that as a marker for xterm(1)-like, assume that
if the terminfo(5) entry already has XT or the clear capability starts
with CSI then the terminal is VT100-like and it should be safe to send
DA requests. The DA responses trigger additional features being added.
-rw-r--r-- | options-table.c | 2 | ||||
-rw-r--r-- | tty-features.c | 105 | ||||
-rw-r--r-- | tty-term.c | 30 |
3 files changed, 110 insertions, 27 deletions
diff --git a/options-table.c b/options-table.c index 23e5af6f..eaa7c2a7 100644 --- a/options-table.c +++ b/options-table.c @@ -261,7 +261,7 @@ const struct options_table_entry options_table[] = { .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_SERVER, .flags = OPTIONS_TABLE_IS_ARRAY, - .default_str = "tmux*:XT,screen*:XT,xterm*:XT", + .default_str = "", .separator = "," }, diff --git a/tty-features.c b/tty-features.c index 7505c96b..30d3d1a0 100644 --- a/tty-features.c +++ b/tty-features.c @@ -25,15 +25,12 @@ /* * Still hardcoded: - * - bracket paste (sent if application asks for it); * - mouse (under kmous capability); - * - focus events (under XT and focus-events option); * - default colours (under AX or op capabilities); * - AIX colours (under colors >= 16); - * - alternate escape (under XT). + * - alternate escape (if terminal is VT100-like). * * Also: - * - XT is used to decide whether to send DA and XDA; * - DECFRA uses a flag instead of capabilities; * - UTF-8 is a separate flag on the client; needed for unattached clients. */ @@ -51,7 +48,7 @@ static const char *tty_feature_title_capabilities[] = { "fsl=\\a", NULL }; -static struct tty_feature tty_feature_title = { +static const struct tty_feature tty_feature_title = { "title", tty_feature_title_capabilities, 0 @@ -62,7 +59,7 @@ static const char *tty_feature_clipboard_capabilities[] = { "Ms=\\E]52;%p1%s;%p2%s\\a", NULL }; -static struct tty_feature tty_feature_clipboard = { +static const struct tty_feature tty_feature_clipboard = { "clipboard", tty_feature_clipboard_capabilities, 0 @@ -81,7 +78,7 @@ static const char *tty_feature_rgb_capabilities[] = { "setaf=\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", NULL }; -static struct tty_feature tty_feature_rgb = { +static const struct tty_feature tty_feature_rgb = { "RGB", tty_feature_rgb_capabilities, TERM_256COLOURS|TERM_RGBCOLOURS @@ -94,7 +91,7 @@ static const char *tty_feature_256_capabilities[] = { "setaf=\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", NULL }; -static struct tty_feature tty_feature_256 = { +static const struct tty_feature tty_feature_256 = { "256", tty_feature_256_capabilities, TERM_256COLOURS @@ -105,7 +102,7 @@ static const char *tty_feature_overline_capabilities[] = { "Smol=\\E[53m", NULL }; -static struct tty_feature tty_feature_overline = { +static const struct tty_feature tty_feature_overline = { "overline", tty_feature_overline_capabilities, 0 @@ -117,19 +114,43 @@ static const char *tty_feature_usstyle_capabilities[] = { "Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m", NULL }; -static struct tty_feature tty_feature_usstyle = { +static const struct tty_feature tty_feature_usstyle = { "usstyle", tty_feature_usstyle_capabilities, 0 }; +/* Terminal supports bracketed paste. */ +static const char *tty_feature_bpaste_capabilities[] = { + "Enbp=\\E[?2004h", + "Dsbp=\\E[?2004l", + NULL +}; +static const struct tty_feature tty_feature_bpaste = { + "bpaste", + tty_feature_bpaste_capabilities, + 0 +}; + +/* Terminal supports focus reporting. */ +static const char *tty_feature_focus_capabilities[] = { + "Enfcs=\\E[?1004h", + "Dsfcs=\\E[?1004l", + NULL +}; +static const struct tty_feature tty_feature_focus = { + "focus", + tty_feature_focus_capabilities, + 0 +}; + /* Terminal supports cursor styles. */ static const char *tty_feature_cstyle_capabilities[] = { "Ss=\\E[%p1%d q", "Se=\\E[2 q", NULL }; -static struct tty_feature tty_feature_cstyle = { +static const struct tty_feature tty_feature_cstyle = { "cstyle", tty_feature_cstyle_capabilities, 0 @@ -141,18 +162,29 @@ static const char *tty_feature_ccolour_capabilities[] = { "Cr=\\E]112\\a", NULL }; -static struct tty_feature tty_feature_ccolour = { +static const struct tty_feature tty_feature_ccolour = { "ccolour", tty_feature_ccolour_capabilities, 0 }; +/* Terminal supports strikethrough. */ +static const char *tty_feature_strikethrough_capabilities[] = { + "smxx=\\E[9m", + NULL +}; +static const struct tty_feature tty_feature_strikethrough = { + "strikethrough", + tty_feature_strikethrough_capabilities, + 0 +}; + /* Terminal supports synchronized updates. */ static const char *tty_feature_sync_capabilities[] = { "Sync=\\EP=%p1%ds\\E\\\\", NULL }; -static struct tty_feature tty_feature_sync = { +static const struct tty_feature tty_feature_sync = { "sync", tty_feature_sync_capabilities, 0 @@ -166,14 +198,14 @@ static const char *tty_feature_margins_capabilities[] = { "Cmg=\\E[%i%p1%d;%p2%ds", NULL }; -static struct tty_feature tty_feature_margins = { +static const struct tty_feature tty_feature_margins = { "margins", tty_feature_margins_capabilities, TERM_DECSLRM }; /* Terminal supports DECFRA rectangle fill. */ -static struct tty_feature tty_feature_rectfill = { +static const struct tty_feature tty_feature_rectfill = { "rectfill", NULL, TERM_DECFRA @@ -182,13 +214,16 @@ static struct tty_feature tty_feature_rectfill = { /* Available terminal features. */ static const struct tty_feature *tty_features[] = { &tty_feature_256, - &tty_feature_clipboard, + &tty_feature_bpaste, &tty_feature_ccolour, + &tty_feature_clipboard, &tty_feature_cstyle, + &tty_feature_focus, &tty_feature_margins, &tty_feature_overline, &tty_feature_rectfill, &tty_feature_rgb, + &tty_feature_strikethrough, &tty_feature_sync, &tty_feature_title, &tty_feature_usstyle @@ -201,7 +236,7 @@ tty_add_features(int *feat, const char *s, const char *separators) char *next, *loop, *copy; u_int i; - log_debug("%s: %s", __func__, s); + log_debug("adding terminal features %s", s); loop = copy = xstrdup(s); while ((next = strsep(&loop, separators)) != NULL) { @@ -275,3 +310,39 @@ tty_apply_features(struct tty_term *term, int feat) term->features |= feat; return (1); } + +void +tty_default_features(int *feat, const char *name, u_int version) +{ + static struct { + const char *name; + u_int version; + const char *features; + } table[] = { +#define TTY_FEATURES_BASE_MODERN_XTERM "256,RGB,bpaste,clipboard,strikethrough,title" + { .name = "mintty", + .features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,margins,overline" + }, + { .name = "tmux", + .features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,focus,overline,usstyle" + }, + { .name = "rxvt-unicode", + .features = "256,bpaste,ccolour,cstyle,title" + }, + { .name = "iTerm2", + .features = TTY_FEATURES_BASE_MODERN_XTERM ",cstyle,margins,sync" + }, + { .name = "XTerm", + .features = TTY_FEATURES_BASE_MODERN_XTERM ",ccolour,cstyle,focus,margins,rectfill" + } + }; + u_int i; + + for (i = 0; i < nitems(table); i++) { + if (strcmp(table[i].name, name) != 0) + continue; + if (version != 0 && version < table[i].version) + continue; + tty_add_features(feat, table[i].features, ","); + } +} @@ -83,6 +83,8 @@ static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_DIM] = { TTYCODE_STRING, "dim" }, [TTYC_DL1] = { TTYCODE_STRING, "dl1" }, [TTYC_DL] = { TTYCODE_STRING, "dl" }, + [TTYC_DSFCS] = { TTYCODE_STRING, "Dsfcs" }, + [TTYC_DSBP] = { TTYCODE_STRING, "Dsbp" }, [TTYC_DSMG] = { TTYCODE_STRING, "Dsmg" }, [TTYC_E3] = { TTYCODE_STRING, "E3" }, [TTYC_ECH] = { TTYCODE_STRING, "ech" }, @@ -90,6 +92,8 @@ static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_EL1] = { TTYCODE_STRING, "el1" }, [TTYC_EL] = { TTYCODE_STRING, "el" }, [TTYC_ENACS] = { TTYCODE_STRING, "enacs" }, + [TTYC_ENBP] = { TTYCODE_STRING, "Enbp" }, + [TTYC_ENFCS] = { TTYCODE_STRING, "Enfcs" }, [TTYC_ENMG] = { TTYCODE_STRING, "Enmg" }, [TTYC_FSL] = { TTYCODE_STRING, "fsl" }, [TTYC_HOME] = { TTYCODE_STRING, "home" }, @@ -545,21 +549,29 @@ tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) goto error; } - /* These can be emulated so one of the two is required. */ - if (!tty_term_has(term, TTYC_CUD1) && !tty_term_has(term, TTYC_CUD)) { - xasprintf(cause, "terminal does not support cud1 or cud"); - goto error; + /* + * If TERM has XT or clear starts with CSI then it is safe to assume + * the terminal is derived from the VT100. This controls whether device + * attributes requests are sent to get more information. + * + * This is a bit of a hack but there aren't that many alternatives. + * Worst case tmux will just fall back to using whatever terminfo(5) + * says without trying to correct anything that is missing. + * + * Also add few features that VT100-like terminals should either + * support or safely ignore. + */ + s = tty_term_string(term, TTYC_CLEAR); + if (tty_term_flag(term, TTYC_XT) || strncmp(s, "\033[", 2) == 0) { + term->flags |= TERM_VT100LIKE; + tty_add_features(feat, "bpaste,focus,title", ","); } /* 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", ":,"); + tty_add_features(feat, "RGB", ","); /* Apply the features and overrides again. */ tty_apply_features(term, *feat); |