mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
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)
This commit is contained in:
@@ -181,11 +181,9 @@ static int create_pty_only(term_T *term, jobopt_T *opt);
|
|||||||
static void term_report_winsize(term_T *term, int rows, int cols);
|
static void term_report_winsize(term_T *term, int rows, int cols);
|
||||||
static void term_free_vterm(term_T *term);
|
static void term_free_vterm(term_T *term);
|
||||||
|
|
||||||
/* The characters that we know (or assume) that the terminal expects for the
|
/* The character that we know (or assume) that the terminal expects for the
|
||||||
* backspace and enter keys. */
|
* backspace key. */
|
||||||
static int term_backspace_char = BS;
|
static int term_backspace_char = BS;
|
||||||
static int term_enter_char = CAR;
|
|
||||||
static int term_nl_does_cr = FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
@@ -651,30 +649,8 @@ free_terminal(buf_T *buf)
|
|||||||
term_write_job_output(term_T *term, char_u *msg, size_t len)
|
term_write_job_output(term_T *term, char_u *msg, size_t len)
|
||||||
{
|
{
|
||||||
VTerm *vterm = term->tl_vterm;
|
VTerm *vterm = term->tl_vterm;
|
||||||
char_u *p;
|
|
||||||
size_t done;
|
|
||||||
size_t len_now;
|
|
||||||
|
|
||||||
if (term_nl_does_cr)
|
vterm_input_write(vterm, (char *)msg, len);
|
||||||
vterm_input_write(vterm, (char *)msg, len);
|
|
||||||
else
|
|
||||||
/* need to convert NL to CR-NL */
|
|
||||||
for (done = 0; done < len; done += len_now)
|
|
||||||
{
|
|
||||||
for (p = msg + done; p < msg + len; )
|
|
||||||
{
|
|
||||||
if (*p == NL)
|
|
||||||
break;
|
|
||||||
p += utf_ptr2len_len(p, (int)(len - (p - msg)));
|
|
||||||
}
|
|
||||||
len_now = p - msg - done;
|
|
||||||
vterm_input_write(vterm, (char *)msg + done, len_now);
|
|
||||||
if (p < msg + len && *p == NL)
|
|
||||||
{
|
|
||||||
vterm_input_write(vterm, "\r\n", 2);
|
|
||||||
++len_now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this invokes the damage callbacks */
|
/* this invokes the damage callbacks */
|
||||||
vterm_screen_flush_damage(vterm_obtain_screen(vterm));
|
vterm_screen_flush_damage(vterm_obtain_screen(vterm));
|
||||||
@@ -760,7 +736,8 @@ term_convert_key(term_T *term, int c, char *buf)
|
|||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case CAR: c = term_enter_char; break;
|
/* don't use VTERM_KEY_ENTER, it may do an unwanted conversion */
|
||||||
|
|
||||||
/* don't use VTERM_KEY_BACKSPACE, it always
|
/* don't use VTERM_KEY_BACKSPACE, it always
|
||||||
* becomes 0x7f DEL */
|
* becomes 0x7f DEL */
|
||||||
case K_BS: c = term_backspace_char; break;
|
case K_BS: c = term_backspace_char; break;
|
||||||
@@ -1534,7 +1511,8 @@ terminal_loop(int blocking)
|
|||||||
int termkey = 0;
|
int termkey = 0;
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
int tty_fd = curbuf->b_term->tl_job->jv_channel->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
|
int tty_fd = curbuf->b_term->tl_job->jv_channel
|
||||||
|
->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Remember the terminal we are sending keys to. However, the terminal
|
/* Remember the terminal we are sending keys to. However, the terminal
|
||||||
@@ -1557,30 +1535,11 @@ terminal_loop(int blocking)
|
|||||||
break;
|
break;
|
||||||
update_cursor(curbuf->b_term, FALSE);
|
update_cursor(curbuf->b_term, FALSE);
|
||||||
|
|
||||||
#ifdef UNIX
|
|
||||||
/*
|
|
||||||
* The shell or another program may change the tty settings. Getting
|
|
||||||
* them for every typed character is a bit of overhead, but it's needed
|
|
||||||
* for the first CR typed, e.g. when Vim starts in a shell.
|
|
||||||
*/
|
|
||||||
if (isatty(tty_fd))
|
|
||||||
{
|
|
||||||
ttyinfo_T info;
|
|
||||||
|
|
||||||
/* Get the current backspace and enter characters of the pty. */
|
|
||||||
if (get_tty_info(tty_fd, &info) == OK)
|
|
||||||
{
|
|
||||||
term_backspace_char = info.backspace;
|
|
||||||
term_enter_char = info.enter;
|
|
||||||
term_nl_does_cr = info.nl_does_cr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
c = term_vgetc();
|
c = term_vgetc();
|
||||||
if (!term_use_loop())
|
if (!term_use_loop())
|
||||||
{
|
{
|
||||||
/* job finished while waiting for a character */
|
/* Job finished while waiting for a character. Push back the
|
||||||
|
* received character. */
|
||||||
if (c != K_IGNORE)
|
if (c != K_IGNORE)
|
||||||
vungetc(c);
|
vungetc(c);
|
||||||
break;
|
break;
|
||||||
@@ -1588,6 +1547,22 @@ terminal_loop(int blocking)
|
|||||||
if (c == K_IGNORE)
|
if (c == K_IGNORE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
#ifdef UNIX
|
||||||
|
/*
|
||||||
|
* The shell or another program may change the tty settings. Getting
|
||||||
|
* them for every typed character is a bit of overhead, but it's needed
|
||||||
|
* for the first character typed, e.g. when Vim starts in a shell.
|
||||||
|
*/
|
||||||
|
if (isatty(tty_fd))
|
||||||
|
{
|
||||||
|
ttyinfo_T info;
|
||||||
|
|
||||||
|
/* Get the current backspace character of the pty. */
|
||||||
|
if (get_tty_info(tty_fd, &info) == OK)
|
||||||
|
term_backspace_char = info.backspace;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WIN3264
|
#ifdef WIN3264
|
||||||
/* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
|
/* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
|
||||||
* Use CTRL-BREAK to kill the job. */
|
* Use CTRL-BREAK to kill the job. */
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1277,
|
||||||
/**/
|
/**/
|
||||||
1276,
|
1276,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user