Skip to content

Commit 26d205d

Browse files
committed
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Problem: Terminal window CR-NL conversions may cause problems. Solution: Avoid most conversions, only fetch the current backspace key value from the tty. (mostly by Ozaki Kiichi, closes #2278)
1 parent a3f7e58 commit 26d205d

2 files changed

Lines changed: 23 additions & 46 deletions

File tree

src/terminal.c

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,9 @@ static int create_pty_only(term_T *term, jobopt_T *opt);
181181
static void term_report_winsize(term_T *term, int rows, int cols);
182182
static void term_free_vterm(term_T *term);
183183

184-
/* The characters that we know (or assume) that the terminal expects for the
185-
* backspace and enter keys. */
184+
/* The character that we know (or assume) that the terminal expects for the
185+
* backspace key. */
186186
static int term_backspace_char = BS;
187-
static int term_enter_char = CAR;
188-
static int term_nl_does_cr = FALSE;
189187

190188

191189
/**************************************
@@ -651,30 +649,8 @@ free_terminal(buf_T *buf)
651649
term_write_job_output(term_T *term, char_u *msg, size_t len)
652650
{
653651
VTerm *vterm = term->tl_vterm;
654-
char_u *p;
655-
size_t done;
656-
size_t len_now;
657652

658-
if (term_nl_does_cr)
659-
vterm_input_write(vterm, (char *)msg, len);
660-
else
661-
/* need to convert NL to CR-NL */
662-
for (done = 0; done < len; done += len_now)
663-
{
664-
for (p = msg + done; p < msg + len; )
665-
{
666-
if (*p == NL)
667-
break;
668-
p += utf_ptr2len_len(p, (int)(len - (p - msg)));
669-
}
670-
len_now = p - msg - done;
671-
vterm_input_write(vterm, (char *)msg + done, len_now);
672-
if (p < msg + len && *p == NL)
673-
{
674-
vterm_input_write(vterm, "\r\n", 2);
675-
++len_now;
676-
}
677-
}
653+
vterm_input_write(vterm, (char *)msg, len);
678654

679655
/* this invokes the damage callbacks */
680656
vterm_screen_flush_damage(vterm_obtain_screen(vterm));
@@ -760,7 +736,8 @@ term_convert_key(term_T *term, int c, char *buf)
760736

761737
switch (c)
762738
{
763-
case CAR: c = term_enter_char; break;
739+
/* don't use VTERM_KEY_ENTER, it may do an unwanted conversion */
740+
764741
/* don't use VTERM_KEY_BACKSPACE, it always
765742
* becomes 0x7f DEL */
766743
case K_BS: c = term_backspace_char; break;
@@ -1534,7 +1511,8 @@ terminal_loop(int blocking)
15341511
int termkey = 0;
15351512
int ret;
15361513
#ifdef UNIX
1537-
int tty_fd = curbuf->b_term->tl_job->jv_channel->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
1514+
int tty_fd = curbuf->b_term->tl_job->jv_channel
1515+
->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
15381516
#endif
15391517

15401518
/* Remember the terminal we are sending keys to. However, the terminal
@@ -1557,37 +1535,34 @@ terminal_loop(int blocking)
15571535
break;
15581536
update_cursor(curbuf->b_term, FALSE);
15591537

1538+
c = term_vgetc();
1539+
if (!term_use_loop())
1540+
{
1541+
/* Job finished while waiting for a character. Push back the
1542+
* received character. */
1543+
if (c != K_IGNORE)
1544+
vungetc(c);
1545+
break;
1546+
}
1547+
if (c == K_IGNORE)
1548+
continue;
1549+
15601550
#ifdef UNIX
15611551
/*
15621552
* The shell or another program may change the tty settings. Getting
15631553
* them for every typed character is a bit of overhead, but it's needed
1564-
* for the first CR typed, e.g. when Vim starts in a shell.
1554+
* for the first character typed, e.g. when Vim starts in a shell.
15651555
*/
15661556
if (isatty(tty_fd))
15671557
{
15681558
ttyinfo_T info;
15691559

1570-
/* Get the current backspace and enter characters of the pty. */
1560+
/* Get the current backspace character of the pty. */
15711561
if (get_tty_info(tty_fd, &info) == OK)
1572-
{
15731562
term_backspace_char = info.backspace;
1574-
term_enter_char = info.enter;
1575-
term_nl_does_cr = info.nl_does_cr;
1576-
}
15771563
}
15781564
#endif
15791565

1580-
c = term_vgetc();
1581-
if (!term_use_loop())
1582-
{
1583-
/* job finished while waiting for a character */
1584-
if (c != K_IGNORE)
1585-
vungetc(c);
1586-
break;
1587-
}
1588-
if (c == K_IGNORE)
1589-
continue;
1590-
15911566
#ifdef WIN3264
15921567
/* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
15931568
* Use CTRL-BREAK to kill the job. */

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1277,
764766
/**/
765767
1276,
766768
/**/

0 commit comments

Comments
 (0)