mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
tui: fix DECSCUSR logic #6997
Fix linuxvt cursor shape codes Fix konsole cursor_shapes (even when inside tmux) Do not trust old VTE terminal lies Closes #6978 Closes #7002 Closes #7049
This commit is contained in:
parent
d42547f322
commit
1f9c139fd3
@ -1256,7 +1256,7 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
bool teraterm = terminfo_is_term_family(term, "teraterm");
|
bool teraterm = terminfo_is_term_family(term, "teraterm");
|
||||||
bool putty = terminfo_is_term_family(term, "putty");
|
bool putty = terminfo_is_term_family(term, "putty");
|
||||||
bool screen = terminfo_is_term_family(term, "screen");
|
bool screen = terminfo_is_term_family(term, "screen");
|
||||||
bool tmux = terminfo_is_term_family(term, "tmux");
|
bool tmux = terminfo_is_term_family(term, "tmux") || !!os_getenv("TMUX");
|
||||||
bool st = terminfo_is_term_family(term, "st");
|
bool st = terminfo_is_term_family(term, "st");
|
||||||
bool gnome = terminfo_is_term_family(term, "gnome")
|
bool gnome = terminfo_is_term_family(term, "gnome")
|
||||||
|| terminfo_is_term_family(term, "vte");
|
|| terminfo_is_term_family(term, "vte");
|
||||||
@ -1270,7 +1270,6 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
bool mate_pretending_xterm = xterm && colorterm
|
bool mate_pretending_xterm = xterm && colorterm
|
||||||
&& strstr(colorterm, "mate-terminal");
|
&& strstr(colorterm, "mate-terminal");
|
||||||
bool true_xterm = xterm && !!xterm_version;
|
bool true_xterm = xterm && !!xterm_version;
|
||||||
bool tmux_pretending_screen = screen && !!os_getenv("TMUX");
|
|
||||||
|
|
||||||
char *fix_normal = (char *)unibi_get_str(ut, unibi_cursor_normal);
|
char *fix_normal = (char *)unibi_get_str(ut, unibi_cursor_normal);
|
||||||
if (fix_normal) {
|
if (fix_normal) {
|
||||||
@ -1347,7 +1346,7 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
// per the screen manual; 2017-04 terminfo.src lacks these.
|
// per the screen manual; 2017-04 terminfo.src lacks these.
|
||||||
unibi_set_if_empty(ut, unibi_to_status_line, "\x1b_");
|
unibi_set_if_empty(ut, unibi_to_status_line, "\x1b_");
|
||||||
unibi_set_if_empty(ut, unibi_from_status_line, "\x1b\\");
|
unibi_set_if_empty(ut, unibi_from_status_line, "\x1b\\");
|
||||||
} else if (terminfo_is_term_family(term, "tmux")) {
|
} else if (tmux) {
|
||||||
unibi_set_if_empty(ut, unibi_to_status_line, "\x1b_");
|
unibi_set_if_empty(ut, unibi_to_status_line, "\x1b_");
|
||||||
unibi_set_if_empty(ut, unibi_from_status_line, "\x1b\\");
|
unibi_set_if_empty(ut, unibi_from_status_line, "\x1b\\");
|
||||||
} else if (terminfo_is_term_family(term, "interix")) {
|
} else if (terminfo_is_term_family(term, "interix")) {
|
||||||
@ -1408,12 +1407,11 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
unibi_set_str(ut, unibi_set_a_foreground, XTERM_SETAF_256_COLON);
|
unibi_set_str(ut, unibi_set_a_foreground, XTERM_SETAF_256_COLON);
|
||||||
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB_256_COLON);
|
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB_256_COLON);
|
||||||
} else if (konsole || xterm || gnome || rxvt || st || putty
|
} else if (konsole || xterm || gnome || rxvt || st || putty
|
||||||
|| linuxvt // Linux 4.8+ supports 256-colour SGR.
|
|| linuxvt // Linux 4.8+ supports 256-colour SGR.
|
||||||
|| mate_pretending_xterm || gnome_pretending_xterm
|
|| mate_pretending_xterm || gnome_pretending_xterm
|
||||||
|| tmux || tmux_pretending_screen
|
|| tmux
|
||||||
|| (colorterm && strstr(colorterm, "256"))
|
|| (colorterm && strstr(colorterm, "256"))
|
||||||
|| (term && strstr(term, "256"))
|
|| (term && strstr(term, "256"))) {
|
||||||
) {
|
|
||||||
unibi_set_num(ut, unibi_max_colors, 256);
|
unibi_set_num(ut, unibi_max_colors, 256);
|
||||||
unibi_set_str(ut, unibi_set_a_foreground, XTERM_SETAF_256);
|
unibi_set_str(ut, unibi_set_a_foreground, XTERM_SETAF_256);
|
||||||
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB_256);
|
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB_256);
|
||||||
@ -1429,12 +1427,17 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dickey ncurses terminfo has included the Ss and Se capabilities, pioneered
|
// Some terminals can not currently be trusted to report if they support
|
||||||
// by tmux, since 2011-07-14. So adding them to terminal types, that do
|
// DECSCUSR or not. So we need to have a blacklist for when we should not
|
||||||
// actually have such control sequences but lack the correct definitions in
|
// trust the reported features.
|
||||||
// terminfo, is a fixup, not an augmentation.
|
if (!((vte_version != 0 && vte_version < 3900) || konsole)) {
|
||||||
data->unibi_ext.reset_cursor_style = unibi_find_ext_str(ut, "Se");
|
// Dickey ncurses terminfo has included the Ss and Se capabilities,
|
||||||
data->unibi_ext.set_cursor_style = unibi_find_ext_str(ut, "Ss");
|
// pioneered by tmux, since 2011-07-14. So adding them to terminal types,
|
||||||
|
// that do actually have such control sequences but lack the correct
|
||||||
|
// definitions in terminfo, is a fixup, not an augmentation.
|
||||||
|
data->unibi_ext.reset_cursor_style = unibi_find_ext_str(ut, "Se");
|
||||||
|
data->unibi_ext.set_cursor_style = unibi_find_ext_str(ut, "Ss");
|
||||||
|
}
|
||||||
if (-1 == data->unibi_ext.set_cursor_style) {
|
if (-1 == data->unibi_ext.set_cursor_style) {
|
||||||
// The DECSCUSR sequence to change the cursor shape is widely
|
// The DECSCUSR sequence to change the cursor shape is widely
|
||||||
// supported by several terminal types and should be in many
|
// supported by several terminal types and should be in many
|
||||||
@ -1442,6 +1445,13 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
// https://github.com/gnachman/iTerm2/pull/92 for more.
|
// https://github.com/gnachman/iTerm2/pull/92 for more.
|
||||||
// xterm even has an extended version that has a vertical bar.
|
// xterm even has an extended version that has a vertical bar.
|
||||||
if (true_xterm // per xterm ctlseqs doco (since version 282)
|
if (true_xterm // per xterm ctlseqs doco (since version 282)
|
||||||
|
// per MinTTY 0.4.3-1 release notes from 2009
|
||||||
|
|| putty
|
||||||
|
// per https://bugzilla.gnome.org/show_bug.cgi?id=720821
|
||||||
|
|| (vte_version >= 3900)
|
||||||
|
|| tmux // per tmux manual page
|
||||||
|
// https://lists.gnu.org/archive/html/screen-devel/2013-03/msg00000.html
|
||||||
|
|| screen
|
||||||
|| rxvt // per command.C
|
|| rxvt // per command.C
|
||||||
// per analysis of VT100Terminal.m
|
// per analysis of VT100Terminal.m
|
||||||
|| iterm || iterm_pretending_xterm
|
|| iterm || iterm_pretending_xterm
|
||||||
@ -1454,50 +1464,34 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
(int)unibi_add_ext_str(ut, "Ss", "\x1b[%p1%d q");
|
(int)unibi_add_ext_str(ut, "Ss", "\x1b[%p1%d q");
|
||||||
if (-1 == data->unibi_ext.reset_cursor_style) {
|
if (-1 == data->unibi_ext.reset_cursor_style) {
|
||||||
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
||||||
"\x1b[ q");
|
"\x1b[ q");
|
||||||
} else if (
|
|
||||||
// per MinTTY 0.4.3-1 release notes from 2009
|
|
||||||
putty
|
|
||||||
// per https://bugzilla.gnome.org/show_bug.cgi?id=720821
|
|
||||||
|| (vte_version >= 3900)
|
|
||||||
// per tmux manual page and per
|
|
||||||
// https://lists.gnu.org/archive/html/screen-devel/2013-03/msg00000.html
|
|
||||||
|| screen) {
|
|
||||||
// Since we use the xterm extension, we must map it to the unextended form
|
|
||||||
data->unibi_ext.set_cursor_style = (int)unibi_add_ext_str(ut, "Ss",
|
|
||||||
"\x1b[%?"
|
|
||||||
"%p1%{4}%>" "%t%p1%{2}%-" // a bit of a bodge for extension values
|
|
||||||
"%e%p1" // the conventional codes are just passed through
|
|
||||||
"%;%d q");
|
|
||||||
if (-1 == data->unibi_ext.reset_cursor_style) {
|
|
||||||
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
|
||||||
"");
|
|
||||||
}
|
|
||||||
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
|
||||||
"\x1b[ q");
|
|
||||||
} else if (linuxvt) {
|
} else if (linuxvt) {
|
||||||
// Linux uses an idiosyncratic escape code to set the cursor shape and
|
// Linux uses an idiosyncratic escape code to set the cursor shape and
|
||||||
// does not support DECSCUSR.
|
// does not support DECSCUSR.
|
||||||
|
// See http://linuxgazette.net/137/anonymous.html for more info
|
||||||
data->unibi_ext.set_cursor_style = (int)unibi_add_ext_str(ut, "Ss",
|
data->unibi_ext.set_cursor_style = (int)unibi_add_ext_str(ut, "Ss",
|
||||||
"\x1b[?"
|
"\x1b[?"
|
||||||
"%?"
|
"%?"
|
||||||
// The parameter passed to Ss is the DECSCUSR parameter, so the
|
// The parameter passed to Ss is the DECSCUSR parameter, so the
|
||||||
// terminal capability has to translate into the Linux idiosyncratic
|
// terminal capability has to translate into the Linux idiosyncratic
|
||||||
// parameter.
|
// parameter.
|
||||||
"%p1%{2}%<" "%t%{8}" // blink block
|
//
|
||||||
"%p1%{2}%=" "%t%{24}" // steady block
|
// linuxvt only supports block and underline. It is also only
|
||||||
"%p1%{3}%=" "%t%{1}" // blink underline
|
// possible to have a steady block (no steady underline)
|
||||||
"%p1%{4}%=" "%t%{17}" // steady underline
|
"%p1%{2}%<" "%t%{8}" // blink block
|
||||||
"%p1%{5}%=" "%t%{1}" // blink bar
|
"%e%p1%{2}%=" "%t%{112}" // steady block
|
||||||
"%p1%{6}%=" "%t%{17}" // steady bar
|
"%e%p1%{3}%=" "%t%{4}" // blink underline (set to half block)
|
||||||
"%e%{0}" // anything else
|
"%e%p1%{4}%=" "%t%{4}" // steady underline
|
||||||
|
"%e%p1%{5}%=" "%t%{2}" // blink bar (set to underline)
|
||||||
|
"%e%p1%{6}%=" "%t%{2}" // steady bar
|
||||||
|
"%e%{0}" // anything else
|
||||||
"%;" "%dc");
|
"%;" "%dc");
|
||||||
if (-1 == data->unibi_ext.reset_cursor_style) {
|
if (-1 == data->unibi_ext.reset_cursor_style) {
|
||||||
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
||||||
"\x1b[?c");
|
"\x1b[?c");
|
||||||
@ -1507,17 +1501,17 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|
|||||||
// nonce profile, which has side-effects on temporary font resizing.
|
// nonce profile, which has side-effects on temporary font resizing.
|
||||||
// In an ideal world, Konsole would just support DECSCUSR.
|
// In an ideal world, Konsole would just support DECSCUSR.
|
||||||
data->unibi_ext.set_cursor_style = (int)unibi_add_ext_str(ut, "Ss",
|
data->unibi_ext.set_cursor_style = (int)unibi_add_ext_str(ut, "Ss",
|
||||||
"\x1b]50;CursorShape=%?"
|
TMUX_WRAP(tmux, "\x1b]50;CursorShape=%?"
|
||||||
"%p1%{3}%<" "%t%{0}" // block
|
"%p1%{3}%<" "%t%{0}" // block
|
||||||
"%e%p1%{4}%<" "%t%{2}" // underline
|
"%e%p1%{5}%<" "%t%{2}" // underline
|
||||||
"%e%{1}" // everything else is bar
|
"%e%{1}" // everything else is bar
|
||||||
"%;%d;BlinkingCursorEnabled=%?"
|
"%;%d;BlinkingCursorEnabled=%?"
|
||||||
"%p1%{1}%<" "%t%{1}" // Fortunately if we exclude zero as special,
|
"%p1%{1}%<" "%t%{1}" // Fortunately if we exclude zero as special,
|
||||||
"%e%p1%{1}%&" // in all other cases we can treat bit #0 as a flag.
|
"%e%p1%{1}%&" // in all other cases we can treat bit #0 as a flag.
|
||||||
"%;%d\x07");
|
"%;%d\x07"));
|
||||||
if (-1 == data->unibi_ext.reset_cursor_style) {
|
if (-1 == data->unibi_ext.reset_cursor_style) {
|
||||||
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
data->unibi_ext.reset_cursor_style = (int)unibi_add_ext_str(ut, "Se",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
unibi_set_ext_str(ut, (size_t)data->unibi_ext.reset_cursor_style,
|
||||||
"\x1b]50;\x07");
|
"\x1b]50;\x07");
|
||||||
|
Loading…
Reference in New Issue
Block a user