patch 9.0.0971: escape sequences not recognized without termresponse feature

Problem:    Escape sequences not recognized without the termresponse feature.
Solution:   Recognize escape sequences to avoid display mess up.
This commit is contained in:
Bram Moolenaar
2022-11-29 13:59:13 +00:00
parent 3719989431
commit 6f2a227565
2 changed files with 27 additions and 29 deletions

View File

@ -4720,7 +4720,6 @@ modifiers2keycode(int modifiers, int *key, char_u *string)
return new_slen; return new_slen;
} }
#ifdef FEAT_TERMRESPONSE
/* /*
* Handle a cursor position report. * Handle a cursor position report.
*/ */
@ -4744,18 +4743,18 @@ handle_u7_response(int *arg, char_u *tp UNUSED, int csi_len UNUSED)
// that right away if possible, keeping any // that right away if possible, keeping any
// messages. // messages.
set_option_value_give_err((char_u *)"ambw", 0L, (char_u *)aw, 0); set_option_value_give_err((char_u *)"ambw", 0L, (char_u *)aw, 0);
# ifdef DEBUG_TERMRESPONSE #ifdef DEBUG_TERMRESPONSE
{ {
int r = redraw_asap(UPD_CLEAR); int r = redraw_asap(UPD_CLEAR);
log_tr("set 'ambiwidth', redraw_asap(): %d", r); log_tr("set 'ambiwidth', redraw_asap(): %d", r);
} }
# else #else
redraw_asap(UPD_CLEAR); redraw_asap(UPD_CLEAR);
# endif #endif
# ifdef FEAT_EVAL #ifdef FEAT_EVAL
set_vim_var_string(VV_TERMU7RESP, tp, csi_len); set_vim_var_string(VV_TERMU7RESP, tp, csi_len);
# endif #endif
} }
} }
else if (arg[0] == 3) else if (arg[0] == 3)
@ -5237,9 +5236,9 @@ handle_csi(
handle_version_response(first, arg, argc, tp); handle_version_response(first, arg, argc, tp);
*slen = csi_len; *slen = csi_len;
# ifdef FEAT_EVAL #ifdef FEAT_EVAL
set_vim_var_string(VV_TERMRESPONSE, tp, *slen); set_vim_var_string(VV_TERMRESPONSE, tp, *slen);
# endif #endif
apply_autocmds(EVENT_TERMRESPONSE, apply_autocmds(EVENT_TERMRESPONSE,
NULL, NULL, FALSE, curbuf); NULL, NULL, FALSE, curbuf);
key_name[0] = (int)KS_EXTRA; key_name[0] = (int)KS_EXTRA;
@ -5264,9 +5263,9 @@ handle_csi(
key_name[0] = (int)KS_EXTRA; key_name[0] = (int)KS_EXTRA;
key_name[1] = (int)KE_IGNORE; key_name[1] = (int)KE_IGNORE;
*slen = csi_len; *slen = csi_len;
# ifdef FEAT_EVAL #ifdef FEAT_EVAL
set_vim_var_string(VV_TERMBLINKRESP, tp, *slen); set_vim_var_string(VV_TERMBLINKRESP, tp, *slen);
# endif #endif
} }
// Kitty keyboard protocol status response: CSI ? flags u // Kitty keyboard protocol status response: CSI ? flags u
@ -5373,13 +5372,13 @@ handle_osc(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
char_u *tp_r = tp + j + 7; char_u *tp_r = tp + j + 7;
char_u *tp_g = tp + j + (is_4digit ? 12 : 10); char_u *tp_g = tp + j + (is_4digit ? 12 : 10);
char_u *tp_b = tp + j + (is_4digit ? 17 : 13); char_u *tp_b = tp + j + (is_4digit ? 17 : 13);
# ifdef FEAT_TERMINAL #ifdef FEAT_TERMINAL
int rval, gval, bval; int rval, gval, bval;
rval = hexhex2nr(tp_r); rval = hexhex2nr(tp_r);
gval = hexhex2nr(tp_b); gval = hexhex2nr(tp_b);
bval = hexhex2nr(tp_g); bval = hexhex2nr(tp_g);
# endif #endif
if (is_bg) if (is_bg)
{ {
char *new_bg_val = (3 * '6' < *tp_r + *tp_g + char *new_bg_val = (3 * '6' < *tp_r + *tp_g +
@ -5387,11 +5386,11 @@ handle_osc(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
LOG_TR(("Received RBG response: %s", tp)); LOG_TR(("Received RBG response: %s", tp));
rbg_status.tr_progress = STATUS_GOT; rbg_status.tr_progress = STATUS_GOT;
# ifdef FEAT_TERMINAL #ifdef FEAT_TERMINAL
bg_r = rval; bg_r = rval;
bg_g = gval; bg_g = gval;
bg_b = bval; bg_b = bval;
# endif #endif
if (!option_was_set((char_u *)"bg") if (!option_was_set((char_u *)"bg")
&& STRCMP(p_bg, new_bg_val) != 0) && STRCMP(p_bg, new_bg_val) != 0)
{ {
@ -5402,7 +5401,7 @@ handle_osc(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
redraw_asap(UPD_CLEAR); redraw_asap(UPD_CLEAR);
} }
} }
# ifdef FEAT_TERMINAL #ifdef FEAT_TERMINAL
else else
{ {
LOG_TR(("Received RFG response: %s", tp)); LOG_TR(("Received RFG response: %s", tp));
@ -5411,17 +5410,17 @@ handle_osc(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
fg_g = gval; fg_g = gval;
fg_b = bval; fg_b = bval;
} }
# endif #endif
} }
// got finished code: consume it // got finished code: consume it
key_name[0] = (int)KS_EXTRA; key_name[0] = (int)KS_EXTRA;
key_name[1] = (int)KE_IGNORE; key_name[1] = (int)KE_IGNORE;
*slen = i + 1 + (tp[i] == ESC); *slen = i + 1 + (tp[i] == ESC);
# ifdef FEAT_EVAL #ifdef FEAT_EVAL
set_vim_var_string(is_bg ? VV_TERMRBGRESP set_vim_var_string(is_bg ? VV_TERMRBGRESP
: VV_TERMRFGRESP, tp, *slen); : VV_TERMRFGRESP, tp, *slen);
# endif #endif
break; break;
} }
if (i == len) if (i == len)
@ -5513,9 +5512,9 @@ handle_dcs(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
key_name[0] = (int)KS_EXTRA; key_name[0] = (int)KS_EXTRA;
key_name[1] = (int)KE_IGNORE; key_name[1] = (int)KE_IGNORE;
*slen = i + 1; *slen = i + 1;
# ifdef FEAT_EVAL #ifdef FEAT_EVAL
set_vim_var_string(VV_TERMSTYLERESP, tp, *slen); set_vim_var_string(VV_TERMSTYLERESP, tp, *slen);
# endif #endif
break; break;
} }
} }
@ -5530,7 +5529,6 @@ handle_dcs(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
} }
return OK; return OK;
} }
#endif // FEAT_TERMRESPONSE
/* /*
* Check if typebuf.tb_buf[] contains a terminal key code. * Check if typebuf.tb_buf[] contains a terminal key code.
@ -5831,17 +5829,16 @@ check_termcode(
} }
} }
#ifdef FEAT_TERMRESPONSE
if (key_name[0] == NUL if (key_name[0] == NUL
// Mouse codes of DEC and pterm start with <ESC>[. When // Mouse codes of DEC and pterm start with <ESC>[. When
// detecting the start of these mouse codes they might as well be // detecting the start of these mouse codes they might as well be
// another key code or terminal response. // another key code or terminal response.
# ifdef FEAT_MOUSE_DEC #ifdef FEAT_MOUSE_DEC
|| key_name[0] == KS_DEC_MOUSE || key_name[0] == KS_DEC_MOUSE
# endif #endif
# ifdef FEAT_MOUSE_PTERM #ifdef FEAT_MOUSE_PTERM
|| key_name[0] == KS_PTERM_MOUSE || key_name[0] == KS_PTERM_MOUSE
# endif #endif
) )
{ {
char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1; char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1;
@ -5874,10 +5871,10 @@ check_termcode(
bufsize, buflen, key_name, &slen); bufsize, buflen, key_name, &slen);
if (resp != 0) if (resp != 0)
{ {
# ifdef DEBUG_TERMRESPONSE #ifdef DEBUG_TERMRESPONSE
if (resp == -1) if (resp == -1)
LOG_TR(("Not enough characters for CSI sequence")); LOG_TR(("Not enough characters for CSI sequence"));
# endif #endif
return resp; return resp;
} }
} }
@ -5903,7 +5900,6 @@ check_termcode(
return -1; return -1;
} }
} }
#endif
if (key_name[0] == NUL) if (key_name[0] == NUL)
continue; // No match at this position, try next one continue; // No match at this position, try next one

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
971,
/**/ /**/
970, 970,
/**/ /**/