diff options
author | Jonathan de Boyne Pollard <J.deBoynePollard-newsgroups@NTLWorld.com> | 2017-06-05 22:47:44 +0100 |
---|---|---|
committer | Jonathan de Boyne Pollard <J.deBoynePollard-newsgroups@NTLWorld.com> | 2017-06-05 22:47:44 +0100 |
commit | b22a61cdbba68ae88a58dd39f288a7bb13c5558d (patch) | |
tree | 2c5a51be423ed6d8d6d8047aa61244a8817d04e4 | |
parent | 054b03e07ac8c27f49afba7225a20214697a3720 (diff) | |
download | rneovim-b22a61cdbba68ae88a58dd39f288a7bb13c5558d.tar.gz rneovim-b22a61cdbba68ae88a58dd39f288a7bb13c5558d.tar.bz2 rneovim-b22a61cdbba68ae88a58dd39f288a7bb13c5558d.zip |
tui: Recognize "Tc" terminfo capability.
This is a new convention pioneered by tmux. It does not do much for
nvim; since nvim always looks to see whether it should be making up
"setrgbf" and "setrgbb" capabilities. But it is a way for terminfo to
force this, irrespective of the hardwired list in the code, for more
terminal types. On the gripping hand, updating terminfo descriptions to
actually have "setrgbf" and "setrgbb" capabilities so that nvim never
has to try to invent them in the first place, is as good if not better
an approach for overriding what is baked into the code.
-rw-r--r-- | runtime/doc/term.txt | 24 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 25 |
2 files changed, 39 insertions, 10 deletions
diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt index 2a6b09a9ff..951947d865 100644 --- a/runtime/doc/term.txt +++ b/runtime/doc/term.txt @@ -134,11 +134,25 @@ support it. It uses the same |terminfo| extensions that were proposed by RĂ¼diger Sonderfeld in 2013 for this: "setrgbf" and "setrgbb". If your terminfo definition specifies these, then nothing more is required. -If your terminfo definition is missing them, then Nvim will on a wide range of -terminals resort to using the ISO 8613-6:1994/ITU T.416:1993 control sequences -for setting RGB colours. This includes the "rxvt", "linux", "st", and "iterm" -terminal types, or when Konsole, genuine Xterm, or a terminal emulator that -sets the COLORTERM environment variable to "truecolor" is detected. +If your terminfo definition is missing them, then Nvim will decide whether to +add them to your terminfo definition, using the ISO 8613-6:1994/ITU T.416:1993 +control sequences for setting RGB colours, but modified to use semicolons +instead of colons unless the terminal is known to follow the standard. +(Semicolons cause ambiguities that the standard avoided by specifying colons +as a sub-parameter delimiter. A historical misunderstanding meant that many +terminal emulators ended up using semicolons for many years, though.) + +A new convention, pioneered in 2016 by tmux, is the "Tc" terminfo extension. +If your terminal's terminfo definition has this flag, Nvim will add +constructed "setrgbf" and "setrgbb" capabilities as if they had been in the +terminfo definition. + +If your terminal's terminfo definition does not (yet) have this flag, Nvim +will fall back to looking at the TERM and other environment variables. For +the "rxvt", "linux", "st", and "iterm" terminal types, or when Konsole, +genuine Xterm, or a terminal emulator that sets the COLORTERM environment +variable to "truecolor" is detected, it will also add constructed "setrgbf" +and "setrgbb" capabilities. *xterm-resize* Nvim can resize the terminal display on some terminals that implement an diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 387a340588..2996d634a2 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1212,6 +1212,18 @@ static int unibi_find_ext_str(unibi_term *ut, const char *name) return -1; } +static int unibi_find_ext_bool(unibi_term *ut, const char *name) + { + size_t max = unibi_count_ext_bool(ut); + for (size_t i = 0; i < max; ++i) { + const char * n = unibi_get_ext_bool_name(ut, i); + if (n && 0 == strcmp(n, name)) { + return (int)i; + } + } + return -1; +} + /// Several entries in terminfo are known to be deficient or outright wrong, /// unfortunately; and several terminal emulators falsely announce incorrect /// terminal types. So patch the terminfo records after loading from an @@ -1497,7 +1509,7 @@ static void augment_terminfo(TUIData *data, const char *term, bool iterm_pretending_xterm = xterm && iterm_env; bool true_xterm = xterm && !!xterm_version; bool tmux_wrap = screen && !!os_getenv("TMUX"); - bool truecolor = colorterm + bool old_truecolor_env = colorterm && (0 == strcmp(colorterm, "truecolor") || 0 == strcmp(colorterm, "24bit")); // Only define this capability for terminal types that we know understand it. @@ -1519,17 +1531,20 @@ static void augment_terminfo(TUIData *data, const char *term, // them to terminal types, that do actually have such control sequences but // lack the correct definitions in terminfo, is an augmentation, not a // fixup. See https://gist.github.com/XVilka/8346728 for more about this. + int Tc = unibi_find_ext_bool(ut, "Tc"); + // "standard" means using colons like ISO 8613-6:1994/ITU T.416:1993 says. bool has_standard_rgb = vte_version >= 3600 // per GNOME bug #685759 || iterm || iterm_pretending_xterm // per analysis of VT100Terminal.m || true_xterm; - // "standard" means using colons like ISO 8613-6:1994/ITU T.416:1993 says. - bool has_non_standard_rgb = - linuxvt // Linux 4.8+ supports true-colour SGR. + bool has_non_standard_rgb = -1 != Tc + // terminfo is definitive if it says something. + ? unibi_get_ext_bool(ut, (size_t)Tc) + : linuxvt // Linux 4.8+ supports true-colour SGR. || konsole // per commentary in VT102Emulation.cpp // per http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html || rxvt || st // per experimentation - || truecolor; + || old_truecolor_env; data->unibi_ext.set_rgb_foreground = unibi_find_ext_str(ut, "setrgbf"); if (-1 == data->unibi_ext.set_rgb_foreground) { if (has_standard_rgb) { |