Mercurial > vim
comparison src/term.c @ 31275:0851a1a22a38 v9.0.0971
patch 9.0.0971: escape sequences not recognized without termresponse feature
Commit: https://github.com/vim/vim/commit/6f2a22756536849f9e45caa4ddd62cab4334f065
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 29 13:59:13 2022 +0000
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 29 Nov 2022 15:00:06 +0100 |
parents | d8e7d725a666 |
children | 68d13970fe8b |
comparison
equal
deleted
inserted
replaced
31274:7aed043572f5 | 31275:0851a1a22a38 |
---|---|
4718 } | 4718 } |
4719 } | 4719 } |
4720 return new_slen; | 4720 return new_slen; |
4721 } | 4721 } |
4722 | 4722 |
4723 #ifdef FEAT_TERMRESPONSE | |
4724 /* | 4723 /* |
4725 * Handle a cursor position report. | 4724 * Handle a cursor position report. |
4726 */ | 4725 */ |
4727 static void | 4726 static void |
4728 handle_u7_response(int *arg, char_u *tp UNUSED, int csi_len UNUSED) | 4727 handle_u7_response(int *arg, char_u *tp UNUSED, int csi_len UNUSED) |
4742 { | 4741 { |
4743 // Setting the option causes a screen redraw. Do | 4742 // Setting the option causes a screen redraw. Do |
4744 // that right away if possible, keeping any | 4743 // that right away if possible, keeping any |
4745 // messages. | 4744 // messages. |
4746 set_option_value_give_err((char_u *)"ambw", 0L, (char_u *)aw, 0); | 4745 set_option_value_give_err((char_u *)"ambw", 0L, (char_u *)aw, 0); |
4747 # ifdef DEBUG_TERMRESPONSE | 4746 #ifdef DEBUG_TERMRESPONSE |
4748 { | 4747 { |
4749 int r = redraw_asap(UPD_CLEAR); | 4748 int r = redraw_asap(UPD_CLEAR); |
4750 | 4749 |
4751 log_tr("set 'ambiwidth', redraw_asap(): %d", r); | 4750 log_tr("set 'ambiwidth', redraw_asap(): %d", r); |
4752 } | 4751 } |
4753 # else | 4752 #else |
4754 redraw_asap(UPD_CLEAR); | 4753 redraw_asap(UPD_CLEAR); |
4755 # endif | 4754 #endif |
4756 # ifdef FEAT_EVAL | 4755 #ifdef FEAT_EVAL |
4757 set_vim_var_string(VV_TERMU7RESP, tp, csi_len); | 4756 set_vim_var_string(VV_TERMU7RESP, tp, csi_len); |
4758 # endif | 4757 #endif |
4759 } | 4758 } |
4760 } | 4759 } |
4761 else if (arg[0] == 3) | 4760 else if (arg[0] == 3) |
4762 { | 4761 { |
4763 int value; | 4762 int value; |
5235 else if (*T_CRV != NUL && ap > argp + 1 && trail == 'c') | 5234 else if (*T_CRV != NUL && ap > argp + 1 && trail == 'c') |
5236 { | 5235 { |
5237 handle_version_response(first, arg, argc, tp); | 5236 handle_version_response(first, arg, argc, tp); |
5238 | 5237 |
5239 *slen = csi_len; | 5238 *slen = csi_len; |
5240 # ifdef FEAT_EVAL | 5239 #ifdef FEAT_EVAL |
5241 set_vim_var_string(VV_TERMRESPONSE, tp, *slen); | 5240 set_vim_var_string(VV_TERMRESPONSE, tp, *slen); |
5242 # endif | 5241 #endif |
5243 apply_autocmds(EVENT_TERMRESPONSE, | 5242 apply_autocmds(EVENT_TERMRESPONSE, |
5244 NULL, NULL, FALSE, curbuf); | 5243 NULL, NULL, FALSE, curbuf); |
5245 key_name[0] = (int)KS_EXTRA; | 5244 key_name[0] = (int)KS_EXTRA; |
5246 key_name[1] = (int)KE_IGNORE; | 5245 key_name[1] = (int)KE_IGNORE; |
5247 } | 5246 } |
5262 rbm_status.tr_progress = STATUS_GOT; | 5261 rbm_status.tr_progress = STATUS_GOT; |
5263 LOG_TR(("Received cursor blinking mode response: %s", tp)); | 5262 LOG_TR(("Received cursor blinking mode response: %s", tp)); |
5264 key_name[0] = (int)KS_EXTRA; | 5263 key_name[0] = (int)KS_EXTRA; |
5265 key_name[1] = (int)KE_IGNORE; | 5264 key_name[1] = (int)KE_IGNORE; |
5266 *slen = csi_len; | 5265 *slen = csi_len; |
5267 # ifdef FEAT_EVAL | 5266 #ifdef FEAT_EVAL |
5268 set_vim_var_string(VV_TERMBLINKRESP, tp, *slen); | 5267 set_vim_var_string(VV_TERMBLINKRESP, tp, *slen); |
5269 # endif | 5268 #endif |
5270 } | 5269 } |
5271 | 5270 |
5272 // Kitty keyboard protocol status response: CSI ? flags u | 5271 // Kitty keyboard protocol status response: CSI ? flags u |
5273 else if (first == '?' && argc == 1 && trail == 'u') | 5272 else if (first == '?' && argc == 1 && trail == 'u') |
5274 { | 5273 { |
5371 || (tp[j + 9] == '/' && tp[i + 12 == '/']))) | 5370 || (tp[j + 9] == '/' && tp[i + 12 == '/']))) |
5372 { | 5371 { |
5373 char_u *tp_r = tp + j + 7; | 5372 char_u *tp_r = tp + j + 7; |
5374 char_u *tp_g = tp + j + (is_4digit ? 12 : 10); | 5373 char_u *tp_g = tp + j + (is_4digit ? 12 : 10); |
5375 char_u *tp_b = tp + j + (is_4digit ? 17 : 13); | 5374 char_u *tp_b = tp + j + (is_4digit ? 17 : 13); |
5376 # ifdef FEAT_TERMINAL | 5375 #ifdef FEAT_TERMINAL |
5377 int rval, gval, bval; | 5376 int rval, gval, bval; |
5378 | 5377 |
5379 rval = hexhex2nr(tp_r); | 5378 rval = hexhex2nr(tp_r); |
5380 gval = hexhex2nr(tp_b); | 5379 gval = hexhex2nr(tp_b); |
5381 bval = hexhex2nr(tp_g); | 5380 bval = hexhex2nr(tp_g); |
5382 # endif | 5381 #endif |
5383 if (is_bg) | 5382 if (is_bg) |
5384 { | 5383 { |
5385 char *new_bg_val = (3 * '6' < *tp_r + *tp_g + | 5384 char *new_bg_val = (3 * '6' < *tp_r + *tp_g + |
5386 *tp_b) ? "light" : "dark"; | 5385 *tp_b) ? "light" : "dark"; |
5387 | 5386 |
5388 LOG_TR(("Received RBG response: %s", tp)); | 5387 LOG_TR(("Received RBG response: %s", tp)); |
5389 rbg_status.tr_progress = STATUS_GOT; | 5388 rbg_status.tr_progress = STATUS_GOT; |
5390 # ifdef FEAT_TERMINAL | 5389 #ifdef FEAT_TERMINAL |
5391 bg_r = rval; | 5390 bg_r = rval; |
5392 bg_g = gval; | 5391 bg_g = gval; |
5393 bg_b = bval; | 5392 bg_b = bval; |
5394 # endif | 5393 #endif |
5395 if (!option_was_set((char_u *)"bg") | 5394 if (!option_was_set((char_u *)"bg") |
5396 && STRCMP(p_bg, new_bg_val) != 0) | 5395 && STRCMP(p_bg, new_bg_val) != 0) |
5397 { | 5396 { |
5398 // value differs, apply it | 5397 // value differs, apply it |
5399 set_option_value_give_err((char_u *)"bg", | 5398 set_option_value_give_err((char_u *)"bg", |
5400 0L, (char_u *)new_bg_val, 0); | 5399 0L, (char_u *)new_bg_val, 0); |
5401 reset_option_was_set((char_u *)"bg"); | 5400 reset_option_was_set((char_u *)"bg"); |
5402 redraw_asap(UPD_CLEAR); | 5401 redraw_asap(UPD_CLEAR); |
5403 } | 5402 } |
5404 } | 5403 } |
5405 # ifdef FEAT_TERMINAL | 5404 #ifdef FEAT_TERMINAL |
5406 else | 5405 else |
5407 { | 5406 { |
5408 LOG_TR(("Received RFG response: %s", tp)); | 5407 LOG_TR(("Received RFG response: %s", tp)); |
5409 rfg_status.tr_progress = STATUS_GOT; | 5408 rfg_status.tr_progress = STATUS_GOT; |
5410 fg_r = rval; | 5409 fg_r = rval; |
5411 fg_g = gval; | 5410 fg_g = gval; |
5412 fg_b = bval; | 5411 fg_b = bval; |
5413 } | 5412 } |
5414 # endif | 5413 #endif |
5415 } | 5414 } |
5416 | 5415 |
5417 // got finished code: consume it | 5416 // got finished code: consume it |
5418 key_name[0] = (int)KS_EXTRA; | 5417 key_name[0] = (int)KS_EXTRA; |
5419 key_name[1] = (int)KE_IGNORE; | 5418 key_name[1] = (int)KE_IGNORE; |
5420 *slen = i + 1 + (tp[i] == ESC); | 5419 *slen = i + 1 + (tp[i] == ESC); |
5421 # ifdef FEAT_EVAL | 5420 #ifdef FEAT_EVAL |
5422 set_vim_var_string(is_bg ? VV_TERMRBGRESP | 5421 set_vim_var_string(is_bg ? VV_TERMRBGRESP |
5423 : VV_TERMRFGRESP, tp, *slen); | 5422 : VV_TERMRFGRESP, tp, *slen); |
5424 # endif | 5423 #endif |
5425 break; | 5424 break; |
5426 } | 5425 } |
5427 if (i == len) | 5426 if (i == len) |
5428 { | 5427 { |
5429 LOG_TR(("not enough characters for RB")); | 5428 LOG_TR(("not enough characters for RB")); |
5511 LOG_TR(("Received cursor shape response: %s", tp)); | 5510 LOG_TR(("Received cursor shape response: %s", tp)); |
5512 | 5511 |
5513 key_name[0] = (int)KS_EXTRA; | 5512 key_name[0] = (int)KS_EXTRA; |
5514 key_name[1] = (int)KE_IGNORE; | 5513 key_name[1] = (int)KE_IGNORE; |
5515 *slen = i + 1; | 5514 *slen = i + 1; |
5516 # ifdef FEAT_EVAL | 5515 #ifdef FEAT_EVAL |
5517 set_vim_var_string(VV_TERMSTYLERESP, tp, *slen); | 5516 set_vim_var_string(VV_TERMSTYLERESP, tp, *slen); |
5518 # endif | 5517 #endif |
5519 break; | 5518 break; |
5520 } | 5519 } |
5521 } | 5520 } |
5522 } | 5521 } |
5523 | 5522 |
5528 LOG_TR(("not enough characters for XT")); | 5527 LOG_TR(("not enough characters for XT")); |
5529 return FAIL; | 5528 return FAIL; |
5530 } | 5529 } |
5531 return OK; | 5530 return OK; |
5532 } | 5531 } |
5533 #endif // FEAT_TERMRESPONSE | |
5534 | 5532 |
5535 /* | 5533 /* |
5536 * Check if typebuf.tb_buf[] contains a terminal key code. | 5534 * Check if typebuf.tb_buf[] contains a terminal key code. |
5537 * Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off | 5535 * Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off |
5538 * + "max_offset"]. | 5536 * + "max_offset"]. |
5829 key_name[0] = termcodes[mouse_index_found].name[0]; | 5827 key_name[0] = termcodes[mouse_index_found].name[0]; |
5830 key_name[1] = termcodes[mouse_index_found].name[1]; | 5828 key_name[1] = termcodes[mouse_index_found].name[1]; |
5831 } | 5829 } |
5832 } | 5830 } |
5833 | 5831 |
5834 #ifdef FEAT_TERMRESPONSE | |
5835 if (key_name[0] == NUL | 5832 if (key_name[0] == NUL |
5836 // Mouse codes of DEC and pterm start with <ESC>[. When | 5833 // Mouse codes of DEC and pterm start with <ESC>[. When |
5837 // detecting the start of these mouse codes they might as well be | 5834 // detecting the start of these mouse codes they might as well be |
5838 // another key code or terminal response. | 5835 // another key code or terminal response. |
5839 # ifdef FEAT_MOUSE_DEC | 5836 #ifdef FEAT_MOUSE_DEC |
5840 || key_name[0] == KS_DEC_MOUSE | 5837 || key_name[0] == KS_DEC_MOUSE |
5841 # endif | 5838 #endif |
5842 # ifdef FEAT_MOUSE_PTERM | 5839 #ifdef FEAT_MOUSE_PTERM |
5843 || key_name[0] == KS_PTERM_MOUSE | 5840 || key_name[0] == KS_PTERM_MOUSE |
5844 # endif | 5841 #endif |
5845 ) | 5842 ) |
5846 { | 5843 { |
5847 char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1; | 5844 char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1; |
5848 | 5845 |
5849 /* | 5846 /* |
5872 { | 5869 { |
5873 int resp = handle_csi(tp, len, argp, offset, buf, | 5870 int resp = handle_csi(tp, len, argp, offset, buf, |
5874 bufsize, buflen, key_name, &slen); | 5871 bufsize, buflen, key_name, &slen); |
5875 if (resp != 0) | 5872 if (resp != 0) |
5876 { | 5873 { |
5877 # ifdef DEBUG_TERMRESPONSE | 5874 #ifdef DEBUG_TERMRESPONSE |
5878 if (resp == -1) | 5875 if (resp == -1) |
5879 LOG_TR(("Not enough characters for CSI sequence")); | 5876 LOG_TR(("Not enough characters for CSI sequence")); |
5880 # endif | 5877 #endif |
5881 return resp; | 5878 return resp; |
5882 } | 5879 } |
5883 } | 5880 } |
5884 | 5881 |
5885 // Check for fore/background color response from the terminal, | 5882 // Check for fore/background color response from the terminal, |
5901 { | 5898 { |
5902 if (handle_dcs(tp, argp, len, key_name, &slen) == FAIL) | 5899 if (handle_dcs(tp, argp, len, key_name, &slen) == FAIL) |
5903 return -1; | 5900 return -1; |
5904 } | 5901 } |
5905 } | 5902 } |
5906 #endif | |
5907 | 5903 |
5908 if (key_name[0] == NUL) | 5904 if (key_name[0] == NUL) |
5909 continue; // No match at this position, try next one | 5905 continue; // No match at this position, try next one |
5910 | 5906 |
5911 // We only get here when we have a complete termcode match | 5907 // We only get here when we have a complete termcode match |