Skip to content

Commit 49528da

Browse files
haron13-2019chrisbra
authored andcommitted
patch 9.1.0321: Garbled output on serial terminals with XON/XOFF flow control
Problem: When used terminal with XON/XOFF flow control, vim tries to still make CTRL-S mapping available, which results in severe screen corruption, especially on large redraws, and even spurious inputs (John Tsiombikas) Solution: Disallow CTRL-S mapping if such terminal is recognized. Don't remove IXON from the bitmask inversion. (Anton Sharonov) *** When started like this: TERM=vt420 vim :set termcap shows "t_xon=y" map <C-S> :echo "abc"<CR> does nothing (after <C-S> output freezes and subsequent <C-Q> unfreezes it) *** When started like this: TERM=xterm vim :set termcap shows "t_xon=" map <C-S> :echo "abc"<CR> works (after <C-S> one see "abc" string echo-ed) fixes: #12674 closes: #14542 Signed-off-by: Anton Sharonov <anton.sharonov@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 4052474 commit 49528da

10 files changed

Lines changed: 60 additions & 6 deletions

File tree

runtime/doc/tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ $quote eval.txt /*$quote*
11571157
't_vi' term.txt /*'t_vi'*
11581158
't_vs' term.txt /*'t_vs'*
11591159
't_xn' term.txt /*'t_xn'*
1160+
't_xo' term.txt /*'t_xo'*
11601161
't_xs' term.txt /*'t_xs'*
11611162
'ta' options.txt /*'ta'*
11621163
'tabline' options.txt /*'tabline'*
@@ -10403,6 +10404,7 @@ t_ve term.txt /*t_ve*
1040310404
t_vi term.txt /*t_vi*
1040410405
t_vs term.txt /*t_vs*
1040510406
t_xn term.txt /*t_xn*
10407+
t_xo term.txt /*t_xo*
1040610408
t_xs term.txt /*t_xs*
1040710409
tab intro.txt /*tab*
1040810410
tab-page tabpage.txt /*tab-page*

runtime/doc/term.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*term.txt* For Vim version 9.1. Last change: 2024 Feb 28
1+
*term.txt* For Vim version 9.1. Last change: 2024 Apr 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -382,7 +382,7 @@ The options are listed below. The associated termcap code is always equal to
382382
the last two characters of the option name. Only one termcap code is
383383
required: Cursor motion, 't_cm'.
384384

385-
The options 't_da', 't_db', 't_ms', 't_xs', 't_xn' represent flags in the
385+
The options 't_da', 't_db', 't_ms', 't_xs', 't_xn', 't_xo' represent flags in the
386386
termcap. When the termcap flag is present, the option will be set to "y".
387387
But any non-empty string means that the flag is set. An empty string means
388388
that the flag is not set. 't_CS' works like this too, but it isn't a termcap
@@ -441,6 +441,11 @@ OUTPUT CODES *terminal-output-codes*
441441
*t_xn* *'t_xn'*
442442
t_xn if non-empty, writing a character at the last screen cell
443443
does not cause scrolling
444+
*t_xo* *'t_xo'*
445+
t_xo if non-empty, terminal uses xon/xoff handshaking, mapping
446+
CTRL-S will not be possible then, since it is used for flow
447+
control (used by vt420 terminal). Setting this flag has only
448+
an effect when starting Vim.
444449
t_ZH italics mode *t_ZH* *'t_ZH'*
445450
t_ZR italics end *t_ZR* *'t_ZR'*
446451

runtime/doc/version9.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2024 Apr 08
1+
*version9.txt* For Vim version 9.1. Last change: 2024 Apr 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41591,6 +41591,7 @@ Commands: ~
4159141591
Options: ~
4159241592

4159341593
'winfixbuf' Keep buffer focused in a window
41594+
't_xo' Terminal uses XON/XOFF handshaking (e.g. vt420).
4159441595

4159541596
==============================================================================
4159641597
INCOMPATIBLE CHANGES *incompatible-9.2*

src/optiondefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,6 +3014,7 @@ static struct vimoption options[] =
30143014
p_term("t_8f", T_8F)
30153015
p_term("t_8b", T_8B)
30163016
p_term("t_8u", T_8U)
3017+
p_term("t_xo", T_XON)
30173018

30183019
// terminal key codes are not in here
30193020

src/os_unix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,8 @@ mch_settmode(tmode_T tmode)
37663766
{
37673767
// ~ICRNL enables typing ^V^M
37683768
// ~IXON disables CTRL-S stopping output, so that it can be mapped.
3769-
tnew.c_iflag &= ~(ICRNL | IXON);
3769+
tnew.c_iflag &= ~(ICRNL |
3770+
(T_XON == NULL || *T_XON == NUL ? IXON : 0));
37703771
tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE
37713772
# if defined(IEXTEN)
37723773
| IEXTEN // IEXTEN enables typing ^V on SOLARIS

src/term.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,8 @@ get_term_entries(int *height, int *width)
17981798
T_DA = (char_u *)"y";
17991799
if ((T_UT == NULL || T_UT == empty_option) && tgetflag("ut") > 0)
18001800
T_UT = (char_u *)"y";
1801+
if ((T_XON == NULL || T_XON == empty_option) && tgetflag("xo") > 0)
1802+
T_XON = (char_u *)"y";
18011803

18021804
/*
18031805
* get key codes

src/termdefs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ enum SpecialKey
115115
KS_SRI, // restore icon text
116116
KS_FD, // disable focus event tracking
117117
KS_FE, // enable focus event tracking
118-
KS_CF // set terminal alternate font
118+
KS_CF, // set terminal alternate font
119+
KS_XON // terminal uses xon/xoff handshaking
119120
};
120121

121-
#define KS_LAST KS_CF
122+
#define KS_LAST KS_XON
122123

123124
/*
124125
* the terminal capabilities are stored in this array
@@ -224,6 +225,7 @@ extern char_u *(term_strings[]); // current terminal strings
224225
#define T_SRI (TERM_STR(KS_SRI)) // restore icon text
225226
#define T_FD (TERM_STR(KS_FD)) // disable focus event tracking
226227
#define T_FE (TERM_STR(KS_FE)) // enable focus event tracking
228+
#define T_XON (TERM_STR(KS_XON)) // terminal uses xon/xoff handshaking
227229

228230
typedef enum {
229231
TMODE_COOK, // terminal mode for external cmds and Ex mode

src/testdir/test_cmdline.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,4 +3792,22 @@ func Test_buffer_completion()
37923792
call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
37933793
endfunc
37943794

3795+
" :set t_??
3796+
func Test_term_option()
3797+
set wildoptions&
3798+
let _cpo = &cpo
3799+
set cpo-=C
3800+
let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm'
3801+
\ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe'
3802+
\ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC'
3803+
\ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr'
3804+
\ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi'
3805+
\ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo t_#2 t_#4 t_%i'
3806+
\ .. ' t_*7 t_@7 t_F1 t_F2 t_k1 t_k2 t_k3 t_k4 t_k5 t_k6 t_k7 t_k8 t_k9 t_k; t_kB t_kD'
3807+
\ .. ' t_kI t_kN t_kP t_kb t_kd t_kh t_kl t_kr t_ku'
3808+
call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
3809+
call assert_equal(expected, @:)
3810+
let &cpo = _cpo
3811+
endfunc
3812+
37953813
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_terminal3.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,5 +931,25 @@ func Test_terminal_term_start_error()
931931
delfunc s:term_start_error
932932
endfunc
933933

934+
func Test_terminal_vt420()
935+
CheckRunVimInTerminal
936+
" For Termcap
937+
CheckUnix
938+
let rows=15
939+
call writefile([':set term=vt420'], 'Xterm420', 'D')
940+
941+
let buf = RunVimInTerminal('-S Xterm420', #{rows: rows})
942+
call TermWait(buf, 100)
943+
call term_sendkeys(buf, ":set t_xo?\<CR>")
944+
call WaitForAssert({-> assert_match('t_xo=y', term_getline(buf, rows))})
945+
call StopVimInTerminal(buf)
946+
947+
call writefile([''], 'Xterm420')
948+
let buf = RunVimInTerminal('-S Xterm420', #{rows: rows})
949+
call TermWait(buf, 100)
950+
call term_sendkeys(buf, ":set t_xo?\<CR>")
951+
call WaitForAssert({-> assert_match('t_xo=\s\+', term_getline(buf, rows))})
952+
call StopVimInTerminal(buf)
953+
endfunc
934954

935955
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
321,
707709
/**/
708710
320,
709711
/**/

0 commit comments

Comments
 (0)