Mercurial > vim
comparison src/term.c @ 22091:9bb1c984c4da v8.2.1595
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Commit: https://github.com/vim/vim/commit/86394aa9720c5e087d85831e42d44e042987fbc0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 5 14:27:24 2020 +0200
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Problem: Cannot easily see what Vim sends to the terminal.
Solution: Write output to the channel log if it contains terminal control
sequences. Avoid warnings for tputs() argument.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Sep 2020 14:30:03 +0200 |
parents | 88070e222e82 |
children | 6c7e4db139a3 |
comparison
equal
deleted
inserted
replaced
22090:a6f58b8aa1af | 22091:9bb1c984c4da |
---|---|
41 # define TPUTSFUNCAST | 41 # define TPUTSFUNCAST |
42 # else | 42 # else |
43 # ifdef HAVE_OUTFUNTYPE | 43 # ifdef HAVE_OUTFUNTYPE |
44 # define TPUTSFUNCAST (outfuntype) | 44 # define TPUTSFUNCAST (outfuntype) |
45 # else | 45 # else |
46 # define TPUTSFUNCAST (int (*)()) | 46 # define TPUTSFUNCAST (int (*)(int)) |
47 # endif | 47 # endif |
48 # endif | 48 # endif |
49 #endif | 49 #endif |
50 | 50 |
51 #undef tgetstr | 51 #undef tgetstr |
2513 { | 2513 { |
2514 // set out_pos to 0 before ui_write, to avoid recursiveness | 2514 // set out_pos to 0 before ui_write, to avoid recursiveness |
2515 len = out_pos; | 2515 len = out_pos; |
2516 out_pos = 0; | 2516 out_pos = 0; |
2517 ui_write(out_buf, len); | 2517 ui_write(out_buf, len); |
2518 #ifdef FEAT_JOB_CHANNEL | |
2519 if (ch_log_output) | |
2520 { | |
2521 out_buf[len] = NUL; | |
2522 ch_log(NULL, "raw terminal output: \"%s\"", out_buf); | |
2523 ch_log_output = FALSE; | |
2524 } | |
2525 #endif | |
2518 } | 2526 } |
2519 } | 2527 } |
2520 | 2528 |
2521 /* | 2529 /* |
2522 * out_flush_cursor(): flush the output buffer and redraw the cursor. | 2530 * out_flush_cursor(): flush the output buffer and redraw the cursor. |
2584 } | 2592 } |
2585 | 2593 |
2586 /* | 2594 /* |
2587 * Output "c" like out_char(), but don't flush when p_wd is set. | 2595 * Output "c" like out_char(), but don't flush when p_wd is set. |
2588 */ | 2596 */ |
2589 static void | 2597 static int |
2590 out_char_nf(unsigned c) | 2598 out_char_nf(int c) |
2591 { | 2599 { |
2592 out_buf[out_pos++] = c; | 2600 out_buf[out_pos++] = (unsigned)c; |
2593 | 2601 |
2594 if (out_pos >= OUT_SIZE) | 2602 if (out_pos >= OUT_SIZE) |
2595 out_flush(); | 2603 out_flush(); |
2604 return (unsigned)c; | |
2596 } | 2605 } |
2597 | 2606 |
2598 /* | 2607 /* |
2599 * A never-padding out_str(). | 2608 * A never-padding out_str(). |
2600 * Use this whenever you don't want to run the string through tputs(). | 2609 * Use this whenever you don't want to run the string through tputs(). |
3029 * Generic function to set window title, using t_ts and t_fs. | 3038 * Generic function to set window title, using t_ts and t_fs. |
3030 */ | 3039 */ |
3031 void | 3040 void |
3032 term_settitle(char_u *title) | 3041 term_settitle(char_u *title) |
3033 { | 3042 { |
3043 #ifdef FEAT_JOB_CHANNEL | |
3044 ch_log_output = TRUE; | |
3045 #endif | |
3034 // t_ts takes one argument: column in status line | 3046 // t_ts takes one argument: column in status line |
3035 OUT_STR(tgoto((char *)T_TS, 0, 0)); // set title start | 3047 OUT_STR(tgoto((char *)T_TS, 0, 0)); // set title start |
3036 out_str_nf(title); | 3048 out_str_nf(title); |
3037 out_str(T_FS); // set title end | 3049 out_str(T_FS); // set title end |
3038 out_flush(); | 3050 out_flush(); |
3527 // Avoid doing this too often, on some terminals the codes are not | 3539 // Avoid doing this too often, on some terminals the codes are not |
3528 // handled properly. | 3540 // handled properly. |
3529 if (termcap_active && tmode != TMODE_SLEEP | 3541 if (termcap_active && tmode != TMODE_SLEEP |
3530 && cur_tmode != TMODE_SLEEP) | 3542 && cur_tmode != TMODE_SLEEP) |
3531 { | 3543 { |
3544 #ifdef FEAT_JOB_CHANNEL | |
3545 ch_log_output = TRUE; | |
3546 #endif | |
3532 if (tmode != TMODE_RAW) | 3547 if (tmode != TMODE_RAW) |
3533 { | 3548 { |
3534 out_str(T_BD); // disable bracketed paste mode | 3549 out_str(T_BD); // disable bracketed paste mode |
3535 out_str(T_CTE); // possibly disables modifyOtherKeys | 3550 out_str(T_CTE); // possibly disables modifyOtherKeys |
3536 } | 3551 } |
3557 void | 3572 void |
3558 starttermcap(void) | 3573 starttermcap(void) |
3559 { | 3574 { |
3560 if (full_screen && !termcap_active) | 3575 if (full_screen && !termcap_active) |
3561 { | 3576 { |
3577 #ifdef FEAT_JOB_CHANNEL | |
3578 ch_log_output = TRUE; | |
3579 #endif | |
3562 out_str(T_TI); // start termcap mode | 3580 out_str(T_TI); // start termcap mode |
3563 out_str(T_CTI); // start "raw" mode | 3581 out_str(T_CTI); // start "raw" mode |
3564 out_str(T_KS); // start "keypad transmit" mode | 3582 out_str(T_KS); // start "keypad transmit" mode |
3565 out_str(T_BE); // enable bracketed paste mode | 3583 out_str(T_BE); // enable bracketed paste mode |
3566 out_flush(); | 3584 out_flush(); |
3609 // Check for termcodes first, otherwise an external program may | 3627 // Check for termcodes first, otherwise an external program may |
3610 // get them. | 3628 // get them. |
3611 check_for_codes_from_term(); | 3629 check_for_codes_from_term(); |
3612 } | 3630 } |
3613 #endif | 3631 #endif |
3632 #ifdef FEAT_JOB_CHANNEL | |
3633 ch_log_output = TRUE; | |
3634 #endif | |
3614 out_str(T_BD); // disable bracketed paste mode | 3635 out_str(T_BD); // disable bracketed paste mode |
3615 out_str(T_KE); // stop "keypad transmit" mode | 3636 out_str(T_KE); // stop "keypad transmit" mode |
3616 out_flush(); | 3637 out_flush(); |
3617 termcap_active = FALSE; | 3638 termcap_active = FALSE; |
3618 cursor_on(); // just in case it is still off | 3639 cursor_on(); // just in case it is still off |
3644 if (crv_status.tr_progress == STATUS_GET | 3665 if (crv_status.tr_progress == STATUS_GET |
3645 && can_get_termresponse() | 3666 && can_get_termresponse() |
3646 && starting == 0 | 3667 && starting == 0 |
3647 && *T_CRV != NUL) | 3668 && *T_CRV != NUL) |
3648 { | 3669 { |
3670 #ifdef FEAT_JOB_CHANNEL | |
3671 ch_log_output = TRUE; | |
3672 #endif | |
3649 LOG_TR(("Sending CRV request")); | 3673 LOG_TR(("Sending CRV request")); |
3650 out_str(T_CRV); | 3674 out_str(T_CRV); |
3651 termrequest_sent(&crv_status); | 3675 termrequest_sent(&crv_status); |
3652 // check for the characters now, otherwise they might be eaten by | 3676 // check for the characters now, otherwise they might be eaten by |
3653 // get_keystroke() | 3677 // get_keystroke() |
3682 // the current cursor position. If the terminal treats \u25bd as | 3706 // the current cursor position. If the terminal treats \u25bd as |
3683 // single width, the position is (1, 1), or if it is treated as double | 3707 // single width, the position is (1, 1), or if it is treated as double |
3684 // width, that will be (1, 2). This function has the side effect that | 3708 // width, that will be (1, 2). This function has the side effect that |
3685 // changes cursor position, so it must be called immediately after | 3709 // changes cursor position, so it must be called immediately after |
3686 // entering termcap mode. | 3710 // entering termcap mode. |
3711 #ifdef FEAT_JOB_CHANNEL | |
3712 ch_log_output = TRUE; | |
3713 #endif | |
3687 LOG_TR(("Sending request for ambiwidth check")); | 3714 LOG_TR(("Sending request for ambiwidth check")); |
3688 // Do this in the second row. In the first row the returned sequence | 3715 // Do this in the second row. In the first row the returned sequence |
3689 // may be CSI 1;2R, which is the same as <S-F3>. | 3716 // may be CSI 1;2R, which is the same as <S-F3>. |
3690 term_windgoto(1, 0); | 3717 term_windgoto(1, 0); |
3691 buf[mb_char2bytes(0x25bd, buf)] = NUL; | 3718 buf[mb_char2bytes(0x25bd, buf)] = NUL; |
3710 // the current cursor position. If the terminal properly handles | 3737 // the current cursor position. If the terminal properly handles |
3711 // unknown DCS string and CSI sequence with intermediate byte, the test | 3738 // unknown DCS string and CSI sequence with intermediate byte, the test |
3712 // sequence is ignored and the cursor does not move. If the terminal | 3739 // sequence is ignored and the cursor does not move. If the terminal |
3713 // handles test sequence incorrectly, a garbage string is displayed and | 3740 // handles test sequence incorrectly, a garbage string is displayed and |
3714 // the cursor does move. | 3741 // the cursor does move. |
3742 #ifdef FEAT_JOB_CHANNEL | |
3743 ch_log_output = TRUE; | |
3744 #endif | |
3715 LOG_TR(("Sending xterm compatibility test sequence.")); | 3745 LOG_TR(("Sending xterm compatibility test sequence.")); |
3716 // Do this in the third row. Second row is used by ambiguous | 3746 // Do this in the third row. Second row is used by ambiguous |
3717 // chararacter width check. | 3747 // chararacter width check. |
3718 term_windgoto(2, 0); | 3748 term_windgoto(2, 0); |
3719 // send the test DCS string. | 3749 // send the test DCS string. |
3760 | 3790 |
3761 # ifdef FEAT_TERMINAL | 3791 # ifdef FEAT_TERMINAL |
3762 // Only request foreground if t_RF is set. | 3792 // Only request foreground if t_RF is set. |
3763 if (rfg_status.tr_progress == STATUS_GET && *T_RFG != NUL) | 3793 if (rfg_status.tr_progress == STATUS_GET && *T_RFG != NUL) |
3764 { | 3794 { |
3795 #ifdef FEAT_JOB_CHANNEL | |
3796 ch_log_output = TRUE; | |
3797 #endif | |
3765 LOG_TR(("Sending FG request")); | 3798 LOG_TR(("Sending FG request")); |
3766 out_str(T_RFG); | 3799 out_str(T_RFG); |
3767 termrequest_sent(&rfg_status); | 3800 termrequest_sent(&rfg_status); |
3768 didit = TRUE; | 3801 didit = TRUE; |
3769 } | 3802 } |
3770 # endif | 3803 # endif |
3771 | 3804 |
3772 // Only request background if t_RB is set. | 3805 // Only request background if t_RB is set. |
3773 if (rbg_status.tr_progress == STATUS_GET && *T_RBG != NUL) | 3806 if (rbg_status.tr_progress == STATUS_GET && *T_RBG != NUL) |
3774 { | 3807 { |
3808 #ifdef FEAT_JOB_CHANNEL | |
3809 ch_log_output = TRUE; | |
3810 #endif | |
3775 LOG_TR(("Sending BG request")); | 3811 LOG_TR(("Sending BG request")); |
3776 out_str(T_RBG); | 3812 out_str(T_RBG); |
3777 termrequest_sent(&rbg_status); | 3813 termrequest_sent(&rbg_status); |
3778 didit = TRUE; | 3814 didit = TRUE; |
3779 } | 3815 } |
3833 void | 3869 void |
3834 scroll_start(void) | 3870 scroll_start(void) |
3835 { | 3871 { |
3836 if (*T_VS != NUL && *T_CVS != NUL) | 3872 if (*T_VS != NUL && *T_CVS != NUL) |
3837 { | 3873 { |
3874 #ifdef FEAT_JOB_CHANNEL | |
3875 ch_log_output = TRUE; | |
3876 #endif | |
3838 out_str(T_VS); | 3877 out_str(T_VS); |
3839 out_str(T_CVS); | 3878 out_str(T_CVS); |
3840 screen_start(); // don't know where cursor is now | 3879 screen_start(); // don't know where cursor is now |
3841 } | 3880 } |
3842 } | 3881 } |
4683 if (rcs_status.tr_progress == STATUS_GET | 4722 if (rcs_status.tr_progress == STATUS_GET |
4684 && term_props[TPR_CURSOR_STYLE].tpr_status == TPR_YES | 4723 && term_props[TPR_CURSOR_STYLE].tpr_status == TPR_YES |
4685 && *T_CSH != NUL | 4724 && *T_CSH != NUL |
4686 && *T_CRS != NUL) | 4725 && *T_CRS != NUL) |
4687 { | 4726 { |
4727 #ifdef FEAT_JOB_CHANNEL | |
4728 ch_log_output = TRUE; | |
4729 #endif | |
4688 LOG_TR(("Sending cursor style request")); | 4730 LOG_TR(("Sending cursor style request")); |
4689 out_str(T_CRS); | 4731 out_str(T_CRS); |
4690 termrequest_sent(&rcs_status); | 4732 termrequest_sent(&rcs_status); |
4691 need_flush = TRUE; | 4733 need_flush = TRUE; |
4692 } | 4734 } |
4697 // Only when getting the cursor style was detected to work. | 4739 // Only when getting the cursor style was detected to work. |
4698 if (rbm_status.tr_progress == STATUS_GET | 4740 if (rbm_status.tr_progress == STATUS_GET |
4699 && term_props[TPR_CURSOR_BLINK].tpr_status == TPR_YES | 4741 && term_props[TPR_CURSOR_BLINK].tpr_status == TPR_YES |
4700 && *T_CRC != NUL) | 4742 && *T_CRC != NUL) |
4701 { | 4743 { |
4744 #ifdef FEAT_JOB_CHANNEL | |
4745 ch_log_output = TRUE; | |
4746 #endif | |
4702 LOG_TR(("Sending cursor blink mode request")); | 4747 LOG_TR(("Sending cursor blink mode request")); |
4703 out_str(T_CRC); | 4748 out_str(T_CRC); |
4704 termrequest_sent(&rbm_status); | 4749 termrequest_sent(&rbm_status); |
4705 need_flush = TRUE; | 4750 need_flush = TRUE; |
4706 } | 4751 } |
6118 // many, there can be a buffer overflow somewhere. | 6163 // many, there can be a buffer overflow somewhere. |
6119 while (xt_index_out < xt_index_in + 10 && key_names[xt_index_out] != NULL) | 6164 while (xt_index_out < xt_index_in + 10 && key_names[xt_index_out] != NULL) |
6120 { | 6165 { |
6121 char *key_name = key_names[xt_index_out]; | 6166 char *key_name = key_names[xt_index_out]; |
6122 | 6167 |
6168 #ifdef FEAT_JOB_CHANNEL | |
6169 ch_log_output = TRUE; | |
6170 #endif | |
6123 LOG_TR(("Requesting XT %d: %s", xt_index_out, key_name)); | 6171 LOG_TR(("Requesting XT %d: %s", xt_index_out, key_name)); |
6124 sprintf(buf, "\033P+q%02x%02x\033\\", key_name[0], key_name[1]); | 6172 sprintf(buf, "\033P+q%02x%02x\033\\", key_name[0], key_name[1]); |
6125 out_str_nf((char_u *)buf); | 6173 out_str_nf((char_u *)buf); |
6126 ++xt_index_out; | 6174 ++xt_index_out; |
6127 } | 6175 } |