comparison src/term.c @ 31825:0d27ddce621d v9.0.1245

patch 9.0.1245: code is indented more than necessary Commit: https://github.com/vim/vim/commit/032713f8299abd92fcfb1e490d1ae5c1ecadde41 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Jan 25 21:05:38 2023 +0000 patch 9.0.1245: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11879)
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Jan 2023 22:15:03 +0100
parents e279b756475b
children b374dfaa8645
comparison
equal deleted inserted replaced
31824:086864270b73 31825:0d27ddce621d
1642 * Set the color count to "val" and redraw if it changed. 1642 * Set the color count to "val" and redraw if it changed.
1643 */ 1643 */
1644 static void 1644 static void
1645 may_adjust_color_count(int val) 1645 may_adjust_color_count(int val)
1646 { 1646 {
1647 if (val != t_colors) 1647 if (val == t_colors)
1648 { 1648 return;
1649 // Nr of colors changed, initialize highlighting and redraw everything. 1649
1650 // This causes a redraw, which usually clears the message. Try keeping 1650 // Nr of colors changed, initialize highlighting and redraw everything.
1651 // the message if it might work. 1651 // This causes a redraw, which usually clears the message. Try keeping
1652 set_keep_msg_from_hist(); 1652 // the message if it might work.
1653 set_color_count(val); 1653 set_keep_msg_from_hist();
1654 init_highlight(TRUE, FALSE); 1654 set_color_count(val);
1655 init_highlight(TRUE, FALSE);
1655 #ifdef DEBUG_TERMRESPONSE 1656 #ifdef DEBUG_TERMRESPONSE
1656 { 1657 {
1657 int r = redraw_asap(UPD_CLEAR); 1658 int r = redraw_asap(UPD_CLEAR);
1658 1659
1659 log_tr("Received t_Co, redraw_asap(): %d", r); 1660 log_tr("Received t_Co, redraw_asap(): %d", r);
1660 } 1661 }
1661 #else 1662 #else
1662 redraw_asap(UPD_CLEAR); 1663 redraw_asap(UPD_CLEAR);
1663 #endif 1664 #endif
1664 }
1665 } 1665 }
1666 1666
1667 #ifdef HAVE_TGETENT 1667 #ifdef HAVE_TGETENT
1668 static char *(key_names[]) = 1668 static char *(key_names[]) =
1669 { 1669 {
2417 long *cp, // pointer to columns 2417 long *cp, // pointer to columns
2418 long *rp) // pointer to rows 2418 long *rp) // pointer to rows
2419 { 2419 {
2420 char_u tbuf[TBUFSZ]; 2420 char_u tbuf[TBUFSZ];
2421 2421
2422 if (T_NAME != NULL && *T_NAME != NUL && invoke_tgetent(tbuf, T_NAME) == NULL) 2422 if (T_NAME == NULL || *T_NAME == NUL
2423 { 2423 || invoke_tgetent(tbuf, T_NAME) != NULL)
2424 if (*cp == 0) 2424 return;
2425 *cp = tgetnum("co"); 2425
2426 if (*rp == 0) 2426 if (*cp == 0)
2427 *rp = tgetnum("li"); 2427 *cp = tgetnum("co");
2428 } 2428 if (*rp == 0)
2429 *rp = tgetnum("li");
2429 } 2430 }
2430 #endif // defined(HAVE_TGETENT) && defined(UNIX) 2431 #endif // defined(HAVE_TGETENT) && defined(UNIX)
2431 2432
2432 /* 2433 /*
2433 * Get a string entry from the termcap and add it to the list of termcodes. 2434 * Get a string entry from the termcap and add it to the list of termcodes.
2567 * <Esc>O -> <M-C-O> 2568 * <Esc>O -> <M-C-O>
2568 */ 2569 */
2569 static int 2570 static int
2570 term_7to8bit(char_u *p) 2571 term_7to8bit(char_u *p)
2571 { 2572 {
2572 if (*p == ESC) 2573 if (*p != ESC)
2573 { 2574 return 0;
2574 if (p[1] == '[') 2575
2575 return CSI; 2576 if (p[1] == '[')
2576 if (p[1] == ']') 2577 return CSI;
2577 return OSC; 2578 else if (p[1] == ']')
2578 if (p[1] == 'O') 2579 return OSC;
2579 return 0x8f; 2580 else if (p[1] == 'O')
2580 } 2581 return 0x8f;
2581 return 0; 2582 return 0;
2582 } 2583 }
2583 2584
2584 #if defined(FEAT_GUI) || defined(PROTO) 2585 #if defined(FEAT_GUI) || defined(PROTO)
2585 int 2586 int
2710 void 2711 void
2711 out_flush(void) 2712 out_flush(void)
2712 { 2713 {
2713 int len; 2714 int len;
2714 2715
2715 if (out_pos != 0) 2716 if (out_pos == 0)
2716 { 2717 return;
2717 // set out_pos to 0 before ui_write, to avoid recursiveness 2718
2718 len = out_pos; 2719 // set out_pos to 0 before ui_write, to avoid recursiveness
2719 out_pos = 0; 2720 len = out_pos;
2720 ui_write(out_buf, len, FALSE); 2721 out_pos = 0;
2722 ui_write(out_buf, len, FALSE);
2721 #ifdef FEAT_EVAL 2723 #ifdef FEAT_EVAL
2722 if (ch_log_output != FALSE) 2724 if (ch_log_output != FALSE)
2723 { 2725 {
2724 out_buf[len] = NUL; 2726 out_buf[len] = NUL;
2725 ch_log(NULL, "raw %s output: \"%s\"", 2727 ch_log(NULL, "raw %s output: \"%s\"",
2726 # ifdef FEAT_GUI 2728 # ifdef FEAT_GUI
2727 (gui.in_use && !gui.dying && !gui.starting) ? "GUI" : 2729 (gui.in_use && !gui.dying && !gui.starting) ? "GUI" :
2728 # endif 2730 # endif
2729 "terminal", 2731 "terminal",
2730 out_buf); 2732 out_buf);
2731 if (ch_log_output == TRUE) 2733 if (ch_log_output == TRUE)
2732 ch_log_output = FALSE; // only log once 2734 ch_log_output = FALSE; // only log once
2733 } 2735 }
2734 #endif 2736 #endif
2735 }
2736 } 2737 }
2737 2738
2738 /* 2739 /*
2739 * out_flush_cursor(): flush the output buffer and redraw the cursor. 2740 * out_flush_cursor(): flush the output buffer and redraw the cursor.
2740 * Does not flush recursively in the GUI to avoid slow drawing. 2741 * Does not flush recursively in the GUI to avoid slow drawing.
2844 * Note: Only for terminal strings. 2845 * Note: Only for terminal strings.
2845 */ 2846 */
2846 void 2847 void
2847 out_str_cf(char_u *s) 2848 out_str_cf(char_u *s)
2848 { 2849 {
2849 if (s != NULL && *s) 2850 if (s == NULL || *s == NUL)
2850 { 2851 return;
2852
2851 #ifdef HAVE_TGETENT 2853 #ifdef HAVE_TGETENT
2852 char_u *p; 2854 char_u *p;
2853 #endif 2855 #endif
2854 2856
2855 #ifdef FEAT_GUI 2857 #ifdef FEAT_GUI
2856 // Don't use tputs() when GUI is used, ncurses crashes. 2858 // Don't use tputs() when GUI is used, ncurses crashes.
2857 if (gui.in_use) 2859 if (gui.in_use)
2858 { 2860 {
2859 out_str_nf(s); 2861 out_str_nf(s);
2860 return; 2862 return;
2861 } 2863 }
2862 #endif 2864 #endif
2863 if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN) 2865 if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
2866 out_flush();
2867 #ifdef HAVE_TGETENT
2868 for (p = s; *s; ++s)
2869 {
2870 // flush just before delay command
2871 if (*s == '$' && *(s + 1) == '<')
2872 {
2873 char_u save_c = *s;
2874 int duration = atoi((char *)s + 2);
2875
2876 *s = NUL;
2877 tputs((char *)p, 1, TPUTSFUNCAST out_char_nf);
2878 *s = save_c;
2864 out_flush(); 2879 out_flush();
2865 #ifdef HAVE_TGETENT 2880 # ifdef ELAPSED_FUNC
2866 for (p = s; *s; ++s) 2881 // Only sleep here if we can limit this happening in
2867 { 2882 // vim_beep().
2868 // flush just before delay command 2883 p = vim_strchr(s, '>');
2869 if (*s == '$' && *(s + 1) == '<') 2884 if (p == NULL || duration <= 0)
2870 { 2885 {
2871 char_u save_c = *s; 2886 // can't parse the time, don't sleep here
2872 int duration = atoi((char *)s + 2); 2887 p = s;
2873 2888 }
2874 *s = NUL; 2889 else
2875 tputs((char *)p, 1, TPUTSFUNCAST out_char_nf); 2890 {
2876 *s = save_c; 2891 ++p;
2877 out_flush(); 2892 do_sleep(duration, FALSE);
2878 # ifdef ELAPSED_FUNC 2893 }
2879 // Only sleep here if we can limit this happening in
2880 // vim_beep().
2881 p = vim_strchr(s, '>');
2882 if (p == NULL || duration <= 0)
2883 {
2884 // can't parse the time, don't sleep here
2885 p = s;
2886 }
2887 else
2888 {
2889 ++p;
2890 do_sleep(duration, FALSE);
2891 }
2892 # else 2894 # else
2893 // Rely on the terminal library to sleep. 2895 // Rely on the terminal library to sleep.
2894 p = s; 2896 p = s;
2895 # endif 2897 # endif
2896 break; 2898 break;
2897 } 2899 }
2898 } 2900 }
2899 tputs((char *)p, 1, TPUTSFUNCAST out_char_nf); 2901 tputs((char *)p, 1, TPUTSFUNCAST out_char_nf);
2900 #else 2902 #else
2901 while (*s) 2903 while (*s)
2902 out_char_nf(*s++); 2904 out_char_nf(*s++);
2903 #endif 2905 #endif
2904 2906
2905 // For testing we write one string at a time. 2907 // For testing we write one string at a time.
2906 if (p_wd) 2908 if (p_wd)
2907 out_flush(); 2909 out_flush();
2908 }
2909 } 2910 }
2910 2911
2911 /* 2912 /*
2912 * out_str(s): Put a character string a byte at a time into the output buffer. 2913 * out_str(s): Put a character string a byte at a time into the output buffer.
2913 * If HAVE_TGETENT is defined use tputs(), the termcap parser. (jw) 2914 * If HAVE_TGETENT is defined use tputs(), the termcap parser. (jw)
2915 * normal text (use functions like msg_puts() and screen_putchar() for that). 2916 * normal text (use functions like msg_puts() and screen_putchar() for that).
2916 */ 2917 */
2917 void 2918 void
2918 out_str(char_u *s) 2919 out_str(char_u *s)
2919 { 2920 {
2920 if (s != NULL && *s) 2921 if (s == NULL || *s == NUL)
2921 { 2922 return;
2923
2922 #ifdef FEAT_GUI 2924 #ifdef FEAT_GUI
2923 // Don't use tputs() when GUI is used, ncurses crashes. 2925 // Don't use tputs() when GUI is used, ncurses crashes.
2924 if (gui.in_use) 2926 if (gui.in_use)
2925 { 2927 {
2926 out_str_nf(s); 2928 out_str_nf(s);
2927 return; 2929 return;
2928 } 2930 }
2929 #endif 2931 #endif
2930 // avoid terminal strings being split up 2932 // avoid terminal strings being split up
2931 if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN) 2933 if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
2932 out_flush(); 2934 out_flush();
2933 #ifdef HAVE_TGETENT 2935 #ifdef HAVE_TGETENT
2934 tputs((char *)s, 1, TPUTSFUNCAST out_char_nf); 2936 tputs((char *)s, 1, TPUTSFUNCAST out_char_nf);
2935 #else 2937 #else
2936 while (*s) 2938 while (*s)
2937 out_char_nf(*s++); 2939 out_char_nf(*s++);
2938 #endif 2940 #endif
2939 2941
2940 // For testing we write one string at a time. 2942 // For testing we write one string at a time.
2941 if (p_wd) 2943 if (p_wd)
2942 out_flush(); 2944 out_flush();
2943 }
2944 } 2945 }
2945 2946
2946 /* 2947 /*
2947 * cursor positioning using termcap parser. (jw) 2948 * cursor positioning using termcap parser. (jw)
2948 */ 2949 */
3466 int i; 3467 int i;
3467 int shift; 3468 int shift;
3468 3469
3469 *val = 0; 3470 *val = 0;
3470 len = get_bytes_from_buf(buf, bytes, (int)sizeof(long_u)); 3471 len = get_bytes_from_buf(buf, bytes, (int)sizeof(long_u));
3471 if (len != -1) 3472 if (len == -1)
3472 { 3473 return -1;
3473 for (i = 0; i < (int)sizeof(long_u); i++) 3474 for (i = 0; i < (int)sizeof(long_u); i++)
3474 { 3475 {
3475 shift = 8 * (sizeof(long_u) - 1 - i); 3476 shift = 8 * (sizeof(long_u) - 1 - i);
3476 *val += (long_u)bytes[i] << shift; 3477 *val += (long_u)bytes[i] << shift;
3477 }
3478 } 3478 }
3479 return len; 3479 return len;
3480 } 3480 }
3481 #endif 3481 #endif
3482 3482
3596 shell_resized_check(void) 3596 shell_resized_check(void)
3597 { 3597 {
3598 int old_Rows = Rows; 3598 int old_Rows = Rows;
3599 int old_Columns = Columns; 3599 int old_Columns = Columns;
3600 3600
3601 if (!exiting 3601 if (exiting
3602 #ifdef FEAT_GUI 3602 #ifdef FEAT_GUI
3603 // Do not get the size when executing a shell command during 3603 // Do not get the size when executing a shell command during
3604 // startup. 3604 // startup.
3605 && !gui.starting 3605 || gui.starting
3606 #endif 3606 #endif
3607 ) 3607 )
3608 { 3608 return;
3609 (void)ui_get_shellsize(); 3609
3610 check_shellsize(); 3610 (void)ui_get_shellsize();
3611 if (old_Rows != Rows || old_Columns != Columns) 3611 check_shellsize();
3612 shell_resized(); 3612 if (old_Rows != Rows || old_Columns != Columns)
3613 } 3613 shell_resized();
3614 } 3614 }
3615 3615
3616 /* 3616 /*
3617 * Set size of the Vim shell. 3617 * Set size of the Vim shell.
3618 * If 'mustset' is TRUE, we must set Rows and Columns, do not get the real 3618 * If 'mustset' is TRUE, we must set Rows and Columns, do not get the real
3841 // don't set the term where gvim was started to any mode 3841 // don't set the term where gvim was started to any mode
3842 if (gui.in_use) 3842 if (gui.in_use)
3843 return; 3843 return;
3844 #endif 3844 #endif
3845 3845
3846 if (full_screen) 3846 if (!full_screen)
3847 { 3847 return;
3848 /* 3848
3849 * When returning after calling a shell cur_tmode is TMODE_UNKNOWN, 3849 /*
3850 * set the terminal to raw mode, even though we think it already is, 3850 * When returning after calling a shell cur_tmode is TMODE_UNKNOWN,
3851 * because the shell program may have reset the terminal mode. 3851 * set the terminal to raw mode, even though we think it already is,
3852 * When we think the terminal is normal, don't try to set it to 3852 * because the shell program may have reset the terminal mode.
3853 * normal again, because that causes problems (logout!) on some 3853 * When we think the terminal is normal, don't try to set it to
3854 * machines. 3854 * normal again, because that causes problems (logout!) on some
3855 */ 3855 * machines.
3856 if (tmode != cur_tmode) 3856 */
3857 { 3857 if (tmode != cur_tmode)
3858 #ifdef FEAT_TERMRESPONSE 3858 {
3859 # ifdef FEAT_GUI
3860 if (!gui.in_use && !gui.starting)
3861 # endif
3862 {
3863 // May need to check for T_CRV response and termcodes, it
3864 // doesn't work in Cooked mode, an external program may get
3865 // them.
3866 if (tmode != TMODE_RAW && termrequest_any_pending())
3867 (void)vpeekc_nomap();
3868 check_for_codes_from_term();
3869 }
3870 #endif
3871 if (tmode != TMODE_RAW)
3872 mch_setmouse(FALSE); // switch mouse off
3873
3874 // Disable bracketed paste and modifyOtherKeys in cooked mode.
3875 // Avoid doing this too often, on some terminals the codes are not
3876 // handled properly.
3877 if (termcap_active && tmode != TMODE_SLEEP
3878 && cur_tmode != TMODE_SLEEP)
3879 {
3880 MAY_WANT_TO_LOG_THIS;
3881
3882 if (tmode != TMODE_RAW)
3883 {
3884 out_str(T_BD); // disable bracketed paste mode
3885 out_str_t_TE(); // possibly disables modifyOtherKeys
3886 }
3887 else
3888 {
3889 out_str_t_BE(); // enable bracketed paste mode (should
3890 // be before mch_settmode().
3891 out_str_t_TI(); // possibly enables modifyOtherKeys
3892 }
3893 }
3894 out_flush();
3895 mch_settmode(tmode); // machine specific function
3896 cur_tmode = tmode;
3897 if (tmode == TMODE_RAW)
3898 setmouse(); // may switch mouse on
3899 out_flush();
3900 }
3901 #ifdef FEAT_TERMRESPONSE
3902 may_req_termresponse();
3903 #endif
3904 }
3905 }
3906
3907 void
3908 starttermcap(void)
3909 {
3910 if (full_screen && !termcap_active)
3911 {
3912 MAY_WANT_TO_LOG_THIS;
3913
3914 out_str(T_TI); // start termcap mode
3915 out_str_t_TI(); // start "raw" mode
3916 out_str(T_KS); // start "keypad transmit" mode
3917 out_str_t_BE(); // enable bracketed paste mode
3918
3919 #if defined(UNIX) || defined(VMS)
3920 // Enable xterm's focus reporting mode when 'esckeys' is set.
3921 if (p_ek && *T_FE != NUL)
3922 out_str(T_FE);
3923 #endif
3924
3925 out_flush();
3926 termcap_active = TRUE;
3927 screen_start(); // don't know where cursor is now
3928 #ifdef FEAT_TERMRESPONSE 3859 #ifdef FEAT_TERMRESPONSE
3929 # ifdef FEAT_GUI 3860 # ifdef FEAT_GUI
3930 if (!gui.in_use && !gui.starting) 3861 if (!gui.in_use && !gui.starting)
3931 # endif 3862 # endif
3932 { 3863 {
3933 may_req_termresponse(); 3864 // May need to check for T_CRV response and termcodes, it
3934 // Immediately check for a response. If t_Co changes, we don't 3865 // doesn't work in Cooked mode, an external program may get
3935 // want to redraw with wrong colors first. 3866 // them.
3936 if (crv_status.tr_progress == STATUS_SENT) 3867 if (tmode != TMODE_RAW && termrequest_any_pending())
3937 check_for_codes_from_term(); 3868 (void)vpeekc_nomap();
3938 } 3869 check_for_codes_from_term();
3939 #endif 3870 }
3940 } 3871 #endif
3872 if (tmode != TMODE_RAW)
3873 mch_setmouse(FALSE); // switch mouse off
3874
3875 // Disable bracketed paste and modifyOtherKeys in cooked mode.
3876 // Avoid doing this too often, on some terminals the codes are not
3877 // handled properly.
3878 if (termcap_active && tmode != TMODE_SLEEP
3879 && cur_tmode != TMODE_SLEEP)
3880 {
3881 MAY_WANT_TO_LOG_THIS;
3882
3883 if (tmode != TMODE_RAW)
3884 {
3885 out_str(T_BD); // disable bracketed paste mode
3886 out_str_t_TE(); // possibly disables modifyOtherKeys
3887 }
3888 else
3889 {
3890 out_str_t_BE(); // enable bracketed paste mode (should
3891 // be before mch_settmode().
3892 out_str_t_TI(); // possibly enables modifyOtherKeys
3893 }
3894 }
3895 out_flush();
3896 mch_settmode(tmode); // machine specific function
3897 cur_tmode = tmode;
3898 if (tmode == TMODE_RAW)
3899 setmouse(); // may switch mouse on
3900 out_flush();
3901 }
3902 #ifdef FEAT_TERMRESPONSE
3903 may_req_termresponse();
3904 #endif
3905 }
3906
3907 void
3908 starttermcap(void)
3909 {
3910 if (!full_screen || termcap_active)
3911 return;
3912
3913 MAY_WANT_TO_LOG_THIS;
3914
3915 out_str(T_TI); // start termcap mode
3916 out_str_t_TI(); // start "raw" mode
3917 out_str(T_KS); // start "keypad transmit" mode
3918 out_str_t_BE(); // enable bracketed paste mode
3919
3920 #if defined(UNIX) || defined(VMS)
3921 // Enable xterm's focus reporting mode when 'esckeys' is set.
3922 if (p_ek && *T_FE != NUL)
3923 out_str(T_FE);
3924 #endif
3925
3926 out_flush();
3927 termcap_active = TRUE;
3928 screen_start(); // don't know where cursor is now
3929 #ifdef FEAT_TERMRESPONSE
3930 # ifdef FEAT_GUI
3931 if (!gui.in_use && !gui.starting)
3932 # endif
3933 {
3934 may_req_termresponse();
3935 // Immediately check for a response. If t_Co changes, we don't
3936 // want to redraw with wrong colors first.
3937 if (crv_status.tr_progress == STATUS_SENT)
3938 check_for_codes_from_term();
3939 }
3940 #endif
3941 } 3941 }
3942 3942
3943 void 3943 void
3944 stoptermcap(void) 3944 stoptermcap(void)
3945 { 3945 {
3946 screen_stop_highlight(); 3946 screen_stop_highlight();
3947 reset_cterm_colors(); 3947 reset_cterm_colors();
3948 if (termcap_active) 3948
3949 { 3949 if (!termcap_active)
3950 return;
3951
3950 #ifdef FEAT_TERMRESPONSE 3952 #ifdef FEAT_TERMRESPONSE
3951 # ifdef FEAT_GUI 3953 # ifdef FEAT_GUI
3952 if (!gui.in_use && !gui.starting) 3954 if (!gui.in_use && !gui.starting)
3953 # endif 3955 # endif
3954 { 3956 {
3955 // May need to discard T_CRV, T_U7 or T_RBG response. 3957 // May need to discard T_CRV, T_U7 or T_RBG response.
3956 if (termrequest_any_pending()) 3958 if (termrequest_any_pending())
3957 { 3959 {
3958 # ifdef UNIX 3960 # ifdef UNIX
3959 // Give the terminal a chance to respond. 3961 // Give the terminal a chance to respond.
3960 mch_delay(100L, 0); 3962 mch_delay(100L, 0);
3961 # endif 3963 # endif
3962 # ifdef TCIFLUSH 3964 # ifdef TCIFLUSH
3963 // Discard data received but not read. 3965 // Discard data received but not read.
3964 if (exiting) 3966 if (exiting)
3965 tcflush(fileno(stdin), TCIFLUSH); 3967 tcflush(fileno(stdin), TCIFLUSH);
3966 # endif 3968 # endif
3967 } 3969 }
3968 // Check for termcodes first, otherwise an external program may 3970 // Check for termcodes first, otherwise an external program may
3969 // get them. 3971 // get them.
3970 check_for_codes_from_term(); 3972 check_for_codes_from_term();
3971 } 3973 }
3972 #endif 3974 #endif
3973 MAY_WANT_TO_LOG_THIS; 3975 MAY_WANT_TO_LOG_THIS;
3974 3976
3975 #if defined(UNIX) || defined(VMS) 3977 #if defined(UNIX) || defined(VMS)
3976 // Disable xterm's focus reporting mode if 'esckeys' is set. 3978 // Disable xterm's focus reporting mode if 'esckeys' is set.
3977 if (p_ek && *T_FD != NUL) 3979 if (p_ek && *T_FD != NUL)
3978 out_str(T_FD); 3980 out_str(T_FD);
3979 #endif 3981 #endif
3980 3982
3981 out_str(T_BD); // disable bracketed paste mode 3983 out_str(T_BD); // disable bracketed paste mode
3982 out_str(T_KE); // stop "keypad transmit" mode 3984 out_str(T_KE); // stop "keypad transmit" mode
3983 out_flush(); 3985 out_flush();
3984 termcap_active = FALSE; 3986 termcap_active = FALSE;
3985 3987
3986 // Output t_te before t_TE, t_te may switch between main and alternate 3988 // Output t_te before t_TE, t_te may switch between main and alternate
3987 // screen and following codes may work on the active screen only. 3989 // screen and following codes may work on the active screen only.
3988 // 3990 //
3989 // When using the Kitty keyboard protocol the main and alternate screen 3991 // When using the Kitty keyboard protocol the main and alternate screen
3990 // use a separate state. If we are (or were) using the Kitty keyboard 3992 // use a separate state. If we are (or were) using the Kitty keyboard
3991 // protocol and t_te is not empty (possibly switching screens) then 3993 // protocol and t_te is not empty (possibly switching screens) then
3992 // output t_TE both before and after outputting t_te. 3994 // output t_TE both before and after outputting t_te.
3993 if (*T_TE != NUL && (kitty_protocol_state == KKPS_ENABLED 3995 if (*T_TE != NUL && (kitty_protocol_state == KKPS_ENABLED
3994 || kitty_protocol_state == KKPS_DISABLED)) 3996 || kitty_protocol_state == KKPS_DISABLED))
3995 out_str_t_TE(); // probably disables the kitty keyboard 3997 out_str_t_TE(); // probably disables the kitty keyboard
3996 // protocol 3998 // protocol
3997 3999
3998 out_str(T_TE); // stop termcap mode 4000 out_str(T_TE); // stop termcap mode
3999 cursor_on(); // just in case it is still off 4001 cursor_on(); // just in case it is still off
4000 out_str_t_TE(); // stop "raw" mode, modifyOtherKeys and 4002 out_str_t_TE(); // stop "raw" mode, modifyOtherKeys and
4001 // Kitty keyboard protocol 4003 // Kitty keyboard protocol
4002 screen_start(); // don't know where cursor is now 4004 screen_start(); // don't know where cursor is now
4003 out_flush(); 4005 out_flush();
4004 }
4005 } 4006 }
4006 4007
4007 #if defined(FEAT_TERMRESPONSE) || defined(PROTO) 4008 #if defined(FEAT_TERMRESPONSE) || defined(PROTO)
4008 /* 4009 /*
4009 * Request version string (for xterm) when needed. 4010 * Request version string (for xterm) when needed.
4217 * Used when starting Vim or returning from a shell. 4218 * Used when starting Vim or returning from a shell.
4218 */ 4219 */
4219 void 4220 void
4220 scroll_start(void) 4221 scroll_start(void)
4221 { 4222 {
4222 if (*T_VS != NUL && *T_CVS != NUL) 4223 if (*T_VS == NUL || *T_CVS == NUL)
4223 { 4224 return;
4224 MAY_WANT_TO_LOG_THIS; 4225
4225 out_str(T_VS); 4226 MAY_WANT_TO_LOG_THIS;
4226 out_str(T_CVS); 4227 out_str(T_VS);
4227 screen_start(); // don't know where cursor is now 4228 out_str(T_CVS);
4228 } 4229 screen_start(); // don't know where cursor is now
4229 } 4230 }
4230 4231
4231 // True if cursor is not visible 4232 // True if cursor is not visible
4232 static int cursor_is_off = FALSE; 4233 static int cursor_is_off = FALSE;
4233 4234
4353 4354
4354 # if defined(FEAT_TERMINAL) || defined(PROTO) 4355 # if defined(FEAT_TERMINAL) || defined(PROTO)
4355 void 4356 void
4356 term_cursor_color(char_u *color) 4357 term_cursor_color(char_u *color)
4357 { 4358 {
4358 if (*T_CSC != NUL) 4359 if (*T_CSC == NUL)
4359 { 4360 return;
4360 out_str(T_CSC); // set cursor color start 4361
4361 out_str_nf(color); 4362 out_str(T_CSC); // set cursor color start
4362 out_str(T_CEC); // set cursor color end 4363 out_str_nf(color);
4363 out_flush(); 4364 out_str(T_CEC); // set cursor color end
4364 } 4365 out_flush();
4365 } 4366 }
4366 # endif 4367 # endif
4367 4368
4368 int 4369 int
4369 blink_state_is_inverted() 4370 blink_state_is_inverted()
4920 static int 4921 static int
4921 modifiers2keycode(int modifiers, int *key, char_u *string) 4922 modifiers2keycode(int modifiers, int *key, char_u *string)
4922 { 4923 {
4923 int new_slen = 0; 4924 int new_slen = 0;
4924 4925
4926 if (modifiers == 0)
4927 return 0;
4928
4929 // Some keys have the modifier included. Need to handle that here to
4930 // make mappings work. This may result in a special key, such as
4931 // K_S_TAB.
4932 *key = simplify_key(*key, &modifiers);
4925 if (modifiers != 0) 4933 if (modifiers != 0)
4926 { 4934 {
4927 // Some keys have the modifier included. Need to handle that here to 4935 string[new_slen++] = K_SPECIAL;
4928 // make mappings work. This may result in a special key, such as 4936 string[new_slen++] = (int)KS_MODIFIER;
4929 // K_S_TAB. 4937 string[new_slen++] = modifiers;
4930 *key = simplify_key(*key, &modifiers);
4931 if (modifiers != 0)
4932 {
4933 string[new_slen++] = K_SPECIAL;
4934 string[new_slen++] = (int)KS_MODIFIER;
4935 string[new_slen++] = modifiers;
4936 }
4937 } 4938 }
4938 return new_slen; 4939 return new_slen;
4939 } 4940 }
4940 4941
4941 /* 4942 /*
6521 * Get the text foreground color, if known. 6522 * Get the text foreground color, if known.
6522 */ 6523 */
6523 void 6524 void
6524 term_get_fg_color(char_u *r, char_u *g, char_u *b) 6525 term_get_fg_color(char_u *r, char_u *g, char_u *b)
6525 { 6526 {
6526 if (rfg_status.tr_progress == STATUS_GOT) 6527 if (rfg_status.tr_progress != STATUS_GOT)
6527 { 6528 return;
6528 *r = fg_r; 6529
6529 *g = fg_g; 6530 *r = fg_r;
6530 *b = fg_b; 6531 *g = fg_g;
6531 } 6532 *b = fg_b;
6532 } 6533 }
6533 6534
6534 /* 6535 /*
6535 * Get the text background color, if known. 6536 * Get the text background color, if known.
6536 */ 6537 */
6537 void 6538 void
6538 term_get_bg_color(char_u *r, char_u *g, char_u *b) 6539 term_get_bg_color(char_u *r, char_u *g, char_u *b)
6539 { 6540 {
6540 if (rbg_status.tr_progress == STATUS_GOT) 6541 if (rbg_status.tr_progress != STATUS_GOT)
6541 { 6542 return;
6542 *r = bg_r; 6543
6543 *g = bg_g; 6544 *r = bg_r;
6544 *b = bg_b; 6545 *g = bg_g;
6545 } 6546 *b = bg_b;
6546 } 6547 }
6547 #endif 6548 #endif
6548 6549
6549 /* 6550 /*
6550 * Replace any terminal code strings in from[] with the equivalent internal 6551 * Replace any terminal code strings in from[] with the equivalent internal
7281 find_first_tcap( 7282 find_first_tcap(
7282 char_u *name, 7283 char_u *name,
7283 int code) 7284 int code)
7284 { 7285 {
7285 tcap_entry_T *p = find_builtin_term(name); 7286 tcap_entry_T *p = find_builtin_term(name);
7286 if (p != NULL) 7287 if (p == NULL)
7287 { 7288 return NULL;
7288 while (p->bt_string != NULL) 7289 while (p->bt_string != NULL)
7289 { 7290 {
7290 if (p->bt_entry == code) 7291 if (p->bt_entry == code)
7291 return p; 7292 return p;
7292 ++p; 7293 ++p;
7293 }
7294 } 7294 }
7295 return NULL; 7295 return NULL;
7296 } 7296 }
7297 # endif 7297 # endif
7298 7298