mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 01:46:29 +00:00
feat(tui): query extended underline support using DECRQSS (#28052)
This commit is contained in:
@@ -553,6 +553,13 @@ static void handle_term_response(TermInput *input, const TermKeyKey *key)
|
||||
if (termkey_interpret_string(input->tk, key, &str) == TERMKEY_RES_KEY) {
|
||||
assert(str != NULL);
|
||||
|
||||
// Handle DECRQSS SGR response for the query from tui_query_extended_underline().
|
||||
// Some terminals include "0" in the attribute list unconditionally; others don't.
|
||||
if (key->type == TERMKEY_TYPE_DCS
|
||||
&& (strnequal(str, S_LEN("1$r4:3m")) || strnequal(str, S_LEN("1$r0;4:3m")))) {
|
||||
tui_enable_extended_underline(input->tui_data);
|
||||
}
|
||||
|
||||
// Send an event to nvim core. This will update the v:termresponse variable
|
||||
// and fire the TermResponse event
|
||||
MAXSIZE_TEMP_ARRAY(args, 2);
|
||||
|
@@ -225,6 +225,26 @@ void tui_handle_term_mode(TUIData *tui, TermMode mode, TermModeState state)
|
||||
}
|
||||
}
|
||||
|
||||
/// Query the terminal emulator to see if it supports extended underline.
|
||||
static void tui_query_extended_underline(TUIData *tui)
|
||||
{
|
||||
// Try to set an undercurl using an SGR sequence, followed by a DECRQSS SGR query.
|
||||
// Reset attributes first, as other code may have set attributes.
|
||||
out(tui, S_LEN("\x1b[0m\x1b[4:3m\x1bP$qm\x1b\\"));
|
||||
tui->print_attr_id = -1;
|
||||
}
|
||||
|
||||
void tui_enable_extended_underline(TUIData *tui)
|
||||
{
|
||||
if (tui->unibi_ext.set_underline_style == -1) {
|
||||
tui->unibi_ext.set_underline_style = (int)unibi_add_ext_str(tui->ut, "ext.set_underline_style",
|
||||
"\x1b[4:%p1%dm");
|
||||
}
|
||||
// Only support colon syntax. #9270
|
||||
tui->unibi_ext.set_underline_color = (int)unibi_add_ext_str(tui->ut, "ext.set_underline_color",
|
||||
"\x1b[58:2::%p1%d:%p2%d:%p3%dm");
|
||||
}
|
||||
|
||||
/// Query the terminal emulator to see if it supports Kitty's keyboard protocol.
|
||||
///
|
||||
/// Write CSI ? u followed by a primary device attributes request (CSI c). If
|
||||
@@ -306,6 +326,7 @@ static void terminfo_start(TUIData *tui)
|
||||
tui->unibi_ext.reset_scroll_region = -1;
|
||||
tui->unibi_ext.set_cursor_style = -1;
|
||||
tui->unibi_ext.reset_cursor_style = -1;
|
||||
tui->unibi_ext.set_underline_style = -1;
|
||||
tui->unibi_ext.set_underline_color = -1;
|
||||
tui->unibi_ext.sync = -1;
|
||||
tui->out_fd = STDOUT_FILENO;
|
||||
@@ -390,6 +411,11 @@ static void terminfo_start(TUIData *tui)
|
||||
// mode 2026
|
||||
tui_request_term_mode(tui, kTermModeSynchronizedOutput);
|
||||
|
||||
if (tui->unibi_ext.set_underline_style == -1) {
|
||||
// Query the terminal to see if it supports extended underline.
|
||||
tui_query_extended_underline(tui);
|
||||
}
|
||||
|
||||
// Query the terminal to see if it supports Kitty's keyboard protocol
|
||||
tui_query_kitty_keyboard(tui);
|
||||
|
||||
@@ -2331,14 +2357,10 @@ static void augment_terminfo(TUIData *tui, const char *term, int vte_version, in
|
||||
if (vte_version >= 5102 || konsolev >= 221170
|
||||
|| (ext_bool_Su != -1 && unibi_get_ext_bool(ut, (size_t)ext_bool_Su))
|
||||
|| (weztermv != NULL && strcmp(weztermv, "20210203-095643") > 0)) {
|
||||
tui->unibi_ext.set_underline_style = (int)unibi_add_ext_str(ut, "ext.set_underline_style",
|
||||
"\x1b[4:%p1%dm");
|
||||
tui_enable_extended_underline(tui);
|
||||
}
|
||||
}
|
||||
if (tui->unibi_ext.set_underline_style != -1) {
|
||||
// Only support colon syntax. #9270
|
||||
tui->unibi_ext.set_underline_color = (int)unibi_add_ext_str(ut, "ext.set_underline_color",
|
||||
"\x1b[58:2::%p1%d:%p2%d:%p3%dm");
|
||||
} else {
|
||||
tui_enable_extended_underline(tui);
|
||||
}
|
||||
|
||||
if (!kitty && (vte_version == 0 || vte_version >= 5400)) {
|
||||
|
Reference in New Issue
Block a user