]> granicus.if.org Git - vim/commitdiff
patch 8.0.1277: terminal window CR-NL conversions may cause problems v8.0.1277
authorBram Moolenaar <Bram@vim.org>
Thu, 9 Nov 2017 16:33:11 +0000 (17:33 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 Nov 2017 16:33:11 +0000 (17:33 +0100)
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)

src/terminal.c
src/version.c

index 4c583977b9227b8dc604b5bc0f496c30dd942744..0012b3bdd19d462eefe2ba87841ca58d4db8aed6 100644 (file)
@@ -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_free_vterm(term_T *term);
 
-/* The characters that we know (or assume) that the terminal expects for the
- * backspace and enter keys. */
+/* The character that we know (or assume) that the terminal expects for the
+ * backspace key. */
 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)
 {
     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);
-    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;
-           }
-       }
+    vterm_input_write(vterm, (char *)msg, len);
 
     /* this invokes the damage callbacks */
     vterm_screen_flush_damage(vterm_obtain_screen(vterm));
@@ -760,7 +736,8 @@ term_convert_key(term_T *term, int c, char *buf)
 
     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
                                 * becomes 0x7f DEL */
        case K_BS:              c = term_backspace_char; break;
@@ -1534,7 +1511,8 @@ terminal_loop(int blocking)
     int                termkey = 0;
     int                ret;
 #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
 
     /* Remember the terminal we are sending keys to.  However, the terminal
@@ -1557,37 +1535,34 @@ terminal_loop(int blocking)
                break;
        update_cursor(curbuf->b_term, FALSE);
 
+       c = term_vgetc();
+       if (!term_use_loop())
+       {
+           /* Job finished while waiting for a character.  Push back the
+            * received character. */
+           if (c != K_IGNORE)
+               vungetc(c);
+           break;
+       }
+       if (c == K_IGNORE)
+           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 CR typed, e.g. when Vim starts in a shell.
+        * for the first character 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. */
+           /* Get the current backspace character 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();
-       if (!term_use_loop())
-       {
-           /* job finished while waiting for a character */
-           if (c != K_IGNORE)
-               vungetc(c);
-           break;
-       }
-       if (c == K_IGNORE)
-           continue;
-
 #ifdef WIN3264
        /* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
         * Use CTRL-BREAK to kill the job. */
index 39bad6c4d3367f20d9c66cfbdb6be67cdd338f4c..b5e45391786871796cf521ee9b6aaa6aad5300a2 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1277,
 /**/
     1276,
 /**/