Mercurial > vim
comparison src/term.c @ 13780:5cf4a504bcc0 v8.0.1762
patch 8.0.1762: terminal debug logging is a bit complicated
commit https://github.com/vim/vim/commit/b255b90503a986931904c23dafb5b6d4e512a17e
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 24 21:40:10 2018 +0200
patch 8.0.1762: terminal debug logging is a bit complicated
Problem: Terminal debug logging is a bit complicated.
Solution: Make log_tr() use variable arguments (Ozaki Kiichi, closes https://github.com/vim/vim/issues/2730)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 24 Apr 2018 21:45:08 +0200 |
parents | 9de2b25932eb |
children | d0d8125ba692 |
comparison
equal
deleted
inserted
replaced
13779:dae7df489b22 | 13780:5cf4a504bcc0 |
---|---|
106 | 106 |
107 # ifdef FEAT_TERMRESPONSE | 107 # ifdef FEAT_TERMRESPONSE |
108 /* Change this to "if 1" to debug what happens with termresponse. */ | 108 /* Change this to "if 1" to debug what happens with termresponse. */ |
109 # if 0 | 109 # if 0 |
110 # define DEBUG_TERMRESPONSE | 110 # define DEBUG_TERMRESPONSE |
111 static void log_tr(char *msg); | 111 static void log_tr(const char *fmt, ...); |
112 # define LOG_TR(msg) log_tr(msg) | 112 # define LOG_TR(msg) log_tr msg |
113 # else | 113 # else |
114 # define LOG_TR(msg) | 114 # define LOG_TR(msg) do { /**/ } while (0) |
115 # endif | 115 # endif |
116 | 116 |
117 # define STATUS_GET 1 /* send request when switching to RAW mode */ | 117 # define STATUS_GET 1 /* send request when switching to RAW mode */ |
118 # define STATUS_SENT 2 /* did send request, waiting for response */ | 118 # define STATUS_SENT 2 /* did send request, waiting for response */ |
119 # define STATUS_GOT 3 /* received response */ | 119 # define STATUS_GOT 3 /* received response */ |
1514 set_keep_msg_from_hist(); | 1514 set_keep_msg_from_hist(); |
1515 set_color_count(val); | 1515 set_color_count(val); |
1516 init_highlight(TRUE, FALSE); | 1516 init_highlight(TRUE, FALSE); |
1517 # ifdef DEBUG_TERMRESPONSE | 1517 # ifdef DEBUG_TERMRESPONSE |
1518 { | 1518 { |
1519 char buf[100]; | 1519 int r = redraw_asap(CLEAR); |
1520 int r = redraw_asap(CLEAR); | 1520 |
1521 | 1521 log_tr("Received t_Co, redraw_asap(): %d", r); |
1522 sprintf(buf, "Received t_Co, redraw_asap(): %d", r); | 1522 } |
1523 log_tr(buf); | 1523 #else |
1524 } | |
1525 # else | |
1526 redraw_asap(CLEAR); | 1524 redraw_asap(CLEAR); |
1527 # endif | 1525 #endif |
1528 } | 1526 } |
1529 } | 1527 } |
1530 #endif | 1528 #endif |
1531 | 1529 |
1532 #ifdef HAVE_TGETENT | 1530 #ifdef HAVE_TGETENT |
1946 ttest(TRUE); /* make sure we have a valid set of terminal codes */ | 1944 ttest(TRUE); /* make sure we have a valid set of terminal codes */ |
1947 | 1945 |
1948 full_screen = TRUE; /* we can use termcap codes from now on */ | 1946 full_screen = TRUE; /* we can use termcap codes from now on */ |
1949 set_term_defaults(); /* use current values as defaults */ | 1947 set_term_defaults(); /* use current values as defaults */ |
1950 #ifdef FEAT_TERMRESPONSE | 1948 #ifdef FEAT_TERMRESPONSE |
1951 LOG_TR("setting crv_status to STATUS_GET"); | 1949 LOG_TR(("setting crv_status to STATUS_GET")); |
1952 crv_status = STATUS_GET; /* Get terminal version later */ | 1950 crv_status = STATUS_GET; /* Get terminal version later */ |
1953 #endif | 1951 #endif |
1954 | 1952 |
1955 /* | 1953 /* |
1956 * Initialize the terminal with the appropriate termcap codes. | 1954 * Initialize the terminal with the appropriate termcap codes. |
3508 if (crv_status == STATUS_GET | 3506 if (crv_status == STATUS_GET |
3509 && can_get_termresponse() | 3507 && can_get_termresponse() |
3510 && starting == 0 | 3508 && starting == 0 |
3511 && *T_CRV != NUL) | 3509 && *T_CRV != NUL) |
3512 { | 3510 { |
3513 LOG_TR("Sending CRV request"); | 3511 LOG_TR(("Sending CRV request")); |
3514 out_str(T_CRV); | 3512 out_str(T_CRV); |
3515 crv_status = STATUS_SENT; | 3513 crv_status = STATUS_SENT; |
3516 /* check for the characters now, otherwise they might be eaten by | 3514 /* check for the characters now, otherwise they might be eaten by |
3517 * get_keystroke() */ | 3515 * get_keystroke() */ |
3518 out_flush(); | 3516 out_flush(); |
3539 && *T_U7 != NUL | 3537 && *T_U7 != NUL |
3540 && !option_was_set((char_u *)"ambiwidth")) | 3538 && !option_was_set((char_u *)"ambiwidth")) |
3541 { | 3539 { |
3542 char_u buf[16]; | 3540 char_u buf[16]; |
3543 | 3541 |
3544 LOG_TR("Sending U7 request"); | 3542 LOG_TR(("Sending U7 request")); |
3545 /* Do this in the second row. In the first row the returned sequence | 3543 /* Do this in the second row. In the first row the returned sequence |
3546 * may be CSI 1;2R, which is the same as <S-F3>. */ | 3544 * may be CSI 1;2R, which is the same as <S-F3>. */ |
3547 term_windgoto(1, 0); | 3545 term_windgoto(1, 0); |
3548 buf[mb_char2bytes(0x25bd, buf)] = 0; | 3546 buf[mb_char2bytes(0x25bd, buf)] = 0; |
3549 out_str(buf); | 3547 out_str(buf); |
3581 | 3579 |
3582 # ifdef FEAT_TERMINAL | 3580 # ifdef FEAT_TERMINAL |
3583 /* Only request foreground if t_RF is set. */ | 3581 /* Only request foreground if t_RF is set. */ |
3584 if (rfg_status == STATUS_GET && *T_RFG != NUL) | 3582 if (rfg_status == STATUS_GET && *T_RFG != NUL) |
3585 { | 3583 { |
3586 LOG_TR("Sending FG request"); | 3584 LOG_TR(("Sending FG request")); |
3587 out_str(T_RFG); | 3585 out_str(T_RFG); |
3588 rfg_status = STATUS_SENT; | 3586 rfg_status = STATUS_SENT; |
3589 didit = TRUE; | 3587 didit = TRUE; |
3590 } | 3588 } |
3591 # endif | 3589 # endif |
3592 | 3590 |
3593 /* Only request background if t_RB is set. */ | 3591 /* Only request background if t_RB is set. */ |
3594 if (rbg_status == STATUS_GET && *T_RBG != NUL) | 3592 if (rbg_status == STATUS_GET && *T_RBG != NUL) |
3595 { | 3593 { |
3596 LOG_TR("Sending BG request"); | 3594 LOG_TR(("Sending BG request")); |
3597 out_str(T_RBG); | 3595 out_str(T_RBG); |
3598 rbg_status = STATUS_SENT; | 3596 rbg_status = STATUS_SENT; |
3599 didit = TRUE; | 3597 didit = TRUE; |
3600 } | 3598 } |
3601 | 3599 |
3609 } | 3607 } |
3610 } | 3608 } |
3611 | 3609 |
3612 # ifdef DEBUG_TERMRESPONSE | 3610 # ifdef DEBUG_TERMRESPONSE |
3613 static void | 3611 static void |
3614 log_tr(char *msg) | 3612 log_tr(const char *fmt, ...) |
3615 { | 3613 { |
3616 static FILE *fd_tr = NULL; | 3614 static FILE *fd_tr = NULL; |
3617 static proftime_T start; | 3615 static proftime_T start; |
3618 proftime_T now; | 3616 proftime_T now; |
3617 va_list ap; | |
3619 | 3618 |
3620 if (fd_tr == NULL) | 3619 if (fd_tr == NULL) |
3621 { | 3620 { |
3622 fd_tr = fopen("termresponse.log", "w"); | 3621 fd_tr = fopen("termresponse.log", "w"); |
3623 profile_start(&start); | 3622 profile_start(&start); |
3624 } | 3623 } |
3625 now = start; | 3624 now = start; |
3626 profile_end(&now); | 3625 profile_end(&now); |
3627 fprintf(fd_tr, "%s: %s %s\n", | 3626 fprintf(fd_tr, "%s: %s ", profile_msg(&now), |
3628 profile_msg(&now), | 3627 must_redraw == NOT_VALID ? "NV" |
3629 must_redraw == NOT_VALID ? "NV" | 3628 : must_redraw == CLEAR ? "CL" : " "); |
3630 : must_redraw == CLEAR ? "CL" : " ", | 3629 va_start(ap, fmt); |
3631 msg); | 3630 vfprintf(fd_tr, fmt, ap); |
3631 va_end(ap); | |
3632 fputc('\n', fd_tr); | |
3633 fflush(fd_tr); | |
3632 } | 3634 } |
3633 # endif | 3635 # endif |
3634 #endif | 3636 #endif |
3635 | 3637 |
3636 /* | 3638 /* |
4177 } | 4179 } |
4178 } | 4180 } |
4179 need_gather = TRUE; /* need to fill termleader[] */ | 4181 need_gather = TRUE; /* need to fill termleader[] */ |
4180 } | 4182 } |
4181 detected_8bit = TRUE; | 4183 detected_8bit = TRUE; |
4182 LOG_TR("Switching to 8 bit"); | 4184 LOG_TR(("Switching to 8 bit")); |
4183 } | 4185 } |
4184 #endif | 4186 #endif |
4185 | 4187 |
4186 #ifdef CHECK_DOUBLE_CLICK | 4188 #ifdef CHECK_DOUBLE_CLICK |
4187 static linenr_T orig_topline = 0; | 4189 static linenr_T orig_topline = 0; |
4510 row_char = tp[i - 1]; | 4512 row_char = tp[i - 1]; |
4511 #endif | 4513 #endif |
4512 } | 4514 } |
4513 if (i == len) | 4515 if (i == len) |
4514 { | 4516 { |
4515 LOG_TR("Not enough characters for CRV"); | 4517 LOG_TR(("Not enough characters for CRV")); |
4516 return -1; | 4518 return -1; |
4517 } | 4519 } |
4518 if (extra > 0) | 4520 if (extra > 0) |
4519 col = atoi((char *)tp + extra); | 4521 col = atoi((char *)tp + extra); |
4520 | 4522 |
4527 { | 4529 { |
4528 if (row_char == '2' && col >= 2) | 4530 if (row_char == '2' && col >= 2) |
4529 { | 4531 { |
4530 char *aw = NULL; | 4532 char *aw = NULL; |
4531 | 4533 |
4532 LOG_TR("Received U7 status"); | 4534 LOG_TR(("Received U7 status: %s", tp)); |
4533 u7_status = STATUS_GOT; | 4535 u7_status = STATUS_GOT; |
4534 did_cursorhold = TRUE; | 4536 did_cursorhold = TRUE; |
4535 if (col == 2) | 4537 if (col == 2) |
4536 aw = "single"; | 4538 aw = "single"; |
4537 else if (col == 3) | 4539 else if (col == 3) |
4543 * messages. */ | 4545 * messages. */ |
4544 set_option_value((char_u *)"ambw", 0L, | 4546 set_option_value((char_u *)"ambw", 0L, |
4545 (char_u *)aw, 0); | 4547 (char_u *)aw, 0); |
4546 # ifdef DEBUG_TERMRESPONSE | 4548 # ifdef DEBUG_TERMRESPONSE |
4547 { | 4549 { |
4548 char buf[100]; | 4550 int r = redraw_asap(CLEAR); |
4549 int r = redraw_asap(CLEAR); | 4551 |
4550 | 4552 log_tr("set 'ambiwidth', redraw_asap(): %d", r); |
4551 sprintf(buf, | |
4552 "set 'ambiwidth', redraw_asap(): %d", | |
4553 r); | |
4554 log_tr(buf); | |
4555 } | 4553 } |
4556 # else | 4554 # else |
4557 redraw_asap(CLEAR); | 4555 redraw_asap(CLEAR); |
4558 # endif | 4556 # endif |
4559 } | 4557 } |
4570 /* eat it when at least one digit and ending in 'c' */ | 4568 /* eat it when at least one digit and ending in 'c' */ |
4571 if (*T_CRV != NUL && i > 2 + (tp[0] != CSI) && tp[i] == 'c') | 4569 if (*T_CRV != NUL && i > 2 + (tp[0] != CSI) && tp[i] == 'c') |
4572 { | 4570 { |
4573 int version = col; | 4571 int version = col; |
4574 | 4572 |
4575 LOG_TR("Received CRV response"); | 4573 LOG_TR(("Received CRV response: %s", tp)); |
4576 crv_status = STATUS_GOT; | 4574 crv_status = STATUS_GOT; |
4577 did_cursorhold = TRUE; | 4575 did_cursorhold = TRUE; |
4578 | 4576 |
4579 /* If this code starts with CSI, you can bet that the | 4577 /* If this code starts with CSI, you can bet that the |
4580 * terminal uses 8-bit codes. */ | 4578 * terminal uses 8-bit codes. */ |
4596 # endif | 4594 # endif |
4597 | 4595 |
4598 /* if xterm version >= 141 try to get termcap codes */ | 4596 /* if xterm version >= 141 try to get termcap codes */ |
4599 if (version >= 141) | 4597 if (version >= 141) |
4600 { | 4598 { |
4601 LOG_TR("Enable checking for XT codes"); | 4599 LOG_TR(("Enable checking for XT codes")); |
4602 check_for_codes = TRUE; | 4600 check_for_codes = TRUE; |
4603 need_gather = TRUE; | 4601 need_gather = TRUE; |
4604 req_codes_from_term(); | 4602 req_codes_from_term(); |
4605 } | 4603 } |
4606 | 4604 |
4686 && version >= 279 | 4684 && version >= 279 |
4687 && !is_not_xterm | 4685 && !is_not_xterm |
4688 && *T_CSH != NUL | 4686 && *T_CSH != NUL |
4689 && *T_CRS != NUL) | 4687 && *T_CRS != NUL) |
4690 { | 4688 { |
4691 LOG_TR("Sending cursor style request"); | 4689 LOG_TR(("Sending cursor style request")); |
4692 out_str(T_CRS); | 4690 out_str(T_CRS); |
4693 rcs_status = STATUS_SENT; | 4691 rcs_status = STATUS_SENT; |
4694 need_flush = TRUE; | 4692 need_flush = TRUE; |
4695 } | 4693 } |
4696 | 4694 |
4699 * echoes the characters to the screen. */ | 4697 * echoes the characters to the screen. */ |
4700 if (rbm_status == STATUS_GET | 4698 if (rbm_status == STATUS_GET |
4701 && !is_not_xterm | 4699 && !is_not_xterm |
4702 && *T_CRC != NUL) | 4700 && *T_CRC != NUL) |
4703 { | 4701 { |
4704 LOG_TR("Sending cursor blink mode request"); | 4702 LOG_TR(("Sending cursor blink mode request")); |
4705 out_str(T_CRC); | 4703 out_str(T_CRC); |
4706 rbm_status = STATUS_SENT; | 4704 rbm_status = STATUS_SENT; |
4707 need_flush = TRUE; | 4705 need_flush = TRUE; |
4708 } | 4706 } |
4709 | 4707 |
4735 && tp[i - 1] == '$' | 4733 && tp[i - 1] == '$' |
4736 && tp[i] == 'y') | 4734 && tp[i] == 'y') |
4737 { | 4735 { |
4738 initial_cursor_blink = (tp[j + 4] == '1'); | 4736 initial_cursor_blink = (tp[j + 4] == '1'); |
4739 rbm_status = STATUS_GOT; | 4737 rbm_status = STATUS_GOT; |
4740 LOG_TR("Received cursor blinking mode response"); | 4738 LOG_TR(("Received cursor blinking mode response: %s", tp)); |
4741 key_name[0] = (int)KS_EXTRA; | 4739 key_name[0] = (int)KS_EXTRA; |
4742 key_name[1] = (int)KE_IGNORE; | 4740 key_name[1] = (int)KE_IGNORE; |
4743 slen = i + 1; | 4741 slen = i + 1; |
4744 # ifdef FEAT_EVAL | 4742 # ifdef FEAT_EVAL |
4745 set_vim_var_string(VV_TERMBLINKRESP, tp, slen); | 4743 set_vim_var_string(VV_TERMBLINKRESP, tp, slen); |
4777 winpos_status = STATUS_GOT; | 4775 winpos_status = STATUS_GOT; |
4778 } | 4776 } |
4779 } | 4777 } |
4780 if (i == len) | 4778 if (i == len) |
4781 { | 4779 { |
4782 LOG_TR("not enough characters for winpos"); | 4780 LOG_TR(("not enough characters for winpos")); |
4783 return -1; | 4781 return -1; |
4784 } | 4782 } |
4785 } | 4783 } |
4786 } | 4784 } |
4787 | 4785 |
4823 if (is_bg) | 4821 if (is_bg) |
4824 { | 4822 { |
4825 char *newval = (3 * '6' < tp[j+7] + tp[j+12] | 4823 char *newval = (3 * '6' < tp[j+7] + tp[j+12] |
4826 + tp[j+17]) ? "light" : "dark"; | 4824 + tp[j+17]) ? "light" : "dark"; |
4827 | 4825 |
4828 LOG_TR("Received RBG response"); | 4826 LOG_TR(("Received RBG response: %s", tp)); |
4829 rbg_status = STATUS_GOT; | 4827 rbg_status = STATUS_GOT; |
4830 #ifdef FEAT_TERMINAL | 4828 #ifdef FEAT_TERMINAL |
4831 bg_r = rval; | 4829 bg_r = rval; |
4832 bg_g = gval; | 4830 bg_g = gval; |
4833 bg_b = bval; | 4831 bg_b = bval; |
4843 } | 4841 } |
4844 } | 4842 } |
4845 #ifdef FEAT_TERMINAL | 4843 #ifdef FEAT_TERMINAL |
4846 else | 4844 else |
4847 { | 4845 { |
4848 LOG_TR("Received RFG response"); | 4846 LOG_TR(("Received RFG response: %s", tp)); |
4849 rfg_status = STATUS_GOT; | 4847 rfg_status = STATUS_GOT; |
4850 fg_r = rval; | 4848 fg_r = rval; |
4851 fg_g = gval; | 4849 fg_g = gval; |
4852 fg_b = bval; | 4850 fg_b = bval; |
4853 } | 4851 } |
4864 # endif | 4862 # endif |
4865 break; | 4863 break; |
4866 } | 4864 } |
4867 if (i == len) | 4865 if (i == len) |
4868 { | 4866 { |
4869 LOG_TR("not enough characters for RB"); | 4867 LOG_TR(("not enough characters for RB")); |
4870 return -1; | 4868 return -1; |
4871 } | 4869 } |
4872 } | 4870 } |
4873 | 4871 |
4874 /* Check for key code response from xterm: | 4872 /* Check for key code response from xterm: |
4938 /* The blink flag is actually inverted, compared to | 4936 /* The blink flag is actually inverted, compared to |
4939 * the value set with T_SH. */ | 4937 * the value set with T_SH. */ |
4940 initial_cursor_shape_blink = | 4938 initial_cursor_shape_blink = |
4941 (number & 1) ? FALSE : TRUE; | 4939 (number & 1) ? FALSE : TRUE; |
4942 rcs_status = STATUS_GOT; | 4940 rcs_status = STATUS_GOT; |
4943 LOG_TR("Received cursor shape response"); | 4941 LOG_TR(("Received cursor shape response: %s", tp)); |
4944 | 4942 |
4945 key_name[0] = (int)KS_EXTRA; | 4943 key_name[0] = (int)KS_EXTRA; |
4946 key_name[1] = (int)KE_IGNORE; | 4944 key_name[1] = (int)KE_IGNORE; |
4947 slen = i + 1; | 4945 slen = i + 1; |
4948 # ifdef FEAT_EVAL | 4946 # ifdef FEAT_EVAL |
4955 | 4953 |
4956 if (i == len) | 4954 if (i == len) |
4957 { | 4955 { |
4958 /* These codes arrive many together, each code can be | 4956 /* These codes arrive many together, each code can be |
4959 * truncated at any point. */ | 4957 * truncated at any point. */ |
4960 LOG_TR("not enough characters for XT"); | 4958 LOG_TR(("not enough characters for XT")); |
4961 return -1; | 4959 return -1; |
4962 } | 4960 } |
4963 } | 4961 } |
4964 } | 4962 } |
4965 #endif | 4963 #endif |
5908 } | 5906 } |
5909 return retval == 0 ? (len + extra + offset) : retval; | 5907 return retval == 0 ? (len + extra + offset) : retval; |
5910 } | 5908 } |
5911 | 5909 |
5912 #ifdef FEAT_TERMRESPONSE | 5910 #ifdef FEAT_TERMRESPONSE |
5913 LOG_TR("normal character"); | 5911 LOG_TR(("normal character")); |
5914 #endif | 5912 #endif |
5915 | 5913 |
5916 return 0; /* no match found */ | 5914 return 0; /* no match found */ |
5917 } | 5915 } |
5918 | 5916 |
6391 | 6389 |
6392 /* Send up to 10 more requests out than we received. Avoid sending too | 6390 /* Send up to 10 more requests out than we received. Avoid sending too |
6393 * many, there can be a buffer overflow somewhere. */ | 6391 * many, there can be a buffer overflow somewhere. */ |
6394 while (xt_index_out < xt_index_in + 10 && key_names[xt_index_out] != NULL) | 6392 while (xt_index_out < xt_index_in + 10 && key_names[xt_index_out] != NULL) |
6395 { | 6393 { |
6396 # ifdef DEBUG_TERMRESPONSE | 6394 char *key_name = key_names[xt_index_out]; |
6397 char dbuf[100]; | 6395 |
6398 | 6396 LOG_TR(("Requesting XT %d: %s", xt_index_out, key_name)); |
6399 sprintf(dbuf, "Requesting XT %d: %s", | 6397 sprintf(buf, "\033P+q%02x%02x\033\\", key_name[0], key_name[1]); |
6400 xt_index_out, key_names[xt_index_out]); | |
6401 log_tr(dbuf); | |
6402 # endif | |
6403 sprintf(buf, "\033P+q%02x%02x\033\\", | |
6404 key_names[xt_index_out][0], key_names[xt_index_out][1]); | |
6405 out_str_nf((char_u *)buf); | 6398 out_str_nf((char_u *)buf); |
6406 ++xt_index_out; | 6399 ++xt_index_out; |
6407 } | 6400 } |
6408 | 6401 |
6409 /* Send the codes out right away. */ | 6402 /* Send the codes out right away. */ |
6442 { | 6435 { |
6443 xt_index_in = i; | 6436 xt_index_in = i; |
6444 break; | 6437 break; |
6445 } | 6438 } |
6446 } | 6439 } |
6447 # ifdef DEBUG_TERMRESPONSE | 6440 |
6448 { | 6441 LOG_TR(("Received XT %d: %s", xt_index_in, (char *)name)); |
6449 char buf[100]; | 6442 |
6450 | |
6451 sprintf(buf, "Received XT %d: %s", xt_index_in, (char *)name); | |
6452 log_tr(buf); | |
6453 } | |
6454 # endif | |
6455 if (key_names[i] != NULL) | 6443 if (key_names[i] != NULL) |
6456 { | 6444 { |
6457 for (i = 8; (c = hexhex2nr(code + i)) >= 0; i += 2) | 6445 for (i = 8; (c = hexhex2nr(code + i)) >= 0; i += 2) |
6458 str[j++] = c; | 6446 str[j++] = c; |
6459 str[j] = NUL; | 6447 str[j] = NUL; |