]> granicus.if.org Git - vim/commitdiff
patch 8.0.1440: terminal window: some vterm responses are delayed v8.0.1440
authorBram Moolenaar <Bram@vim.org>
Tue, 30 Jan 2018 21:31:19 +0000 (22:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 30 Jan 2018 21:31:19 +0000 (22:31 +0100)
Problem:    Terminal window: some vterm responses are delayed.
Solution:   After writing input. check if there is output to read. (Ozaki
            Kiichi, closes #2594)

src/terminal.c
src/testdir/test_search.vim
src/testdir/test_terminal.vim
src/version.c

index 0d6a9571b407a7c37f991b4a2794bb80217aee32..4c0c3de880c951bdeb9f3bfc1244d991eab16d58 100644 (file)
@@ -649,6 +649,29 @@ free_terminal(buf_T *buf)
        in_terminal_loop = NULL;
 }
 
+/*
+ * Get the part that is connected to the tty. Normally this is PART_IN, but
+ * when writing buffer lines to the job it can be another.  This makes it
+ * possible to do "1,5term vim -".
+ */
+    static ch_part_T
+get_tty_part(term_T *term)
+{
+#ifdef UNIX
+    ch_part_T  parts[3] = {PART_IN, PART_OUT, PART_ERR};
+    int                i;
+
+    for (i = 0; i < 3; ++i)
+    {
+       int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
+
+       if (isatty(fd))
+           return parts[i];
+    }
+#endif
+    return PART_IN;
+}
+
 /*
  * Write job output "msg[len]" to the vterm.
  */
@@ -656,9 +679,21 @@ free_terminal(buf_T *buf)
 term_write_job_output(term_T *term, char_u *msg, size_t len)
 {
     VTerm      *vterm = term->tl_vterm;
+    size_t     prevlen = vterm_output_get_buffer_current(vterm);
 
     vterm_input_write(vterm, (char *)msg, len);
 
+    /* flush vterm buffer when vterm responded to control sequence */
+    if (prevlen != vterm_output_get_buffer_current(vterm))
+    {
+       char   buf[KEY_BUF_LEN];
+       size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
+
+       if (curlen > 0)
+           channel_send(term->tl_job->jv_channel, get_tty_part(term),
+                                            (char_u *)buf, (int)curlen, NULL);
+    }
+
     /* this invokes the damage callbacks */
     vterm_screen_flush_damage(vterm_obtain_screen(vterm));
 }
@@ -1238,29 +1273,6 @@ term_vgetc()
     return c;
 }
 
-/*
- * Get the part that is connected to the tty. Normally this is PART_IN, but
- * when writing buffer lines to the job it can be another.  This makes it
- * possible to do "1,5term vim -".
- */
-    static ch_part_T
-get_tty_part(term_T *term)
-{
-#ifdef UNIX
-    ch_part_T  parts[3] = {PART_IN, PART_OUT, PART_ERR};
-    int                i;
-
-    for (i = 0; i < 3; ++i)
-    {
-       int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
-
-       if (isatty(fd))
-           return parts[i];
-    }
-#endif
-    return PART_IN;
-}
-
 /*
  * Send keys to terminal.
  * Return FAIL when the key needs to be handled in Normal mode.
index 9b96b49fdefbea7745845de6cb13d00f3803f09b..130562fc5e395f069b73873b782447c748d1cb9e 100644 (file)
@@ -619,6 +619,8 @@ func Test_search_cmdline_incsearch_highlight_attr()
   let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3})
 
   call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] })
+  " wait for vim to complete initialization
+  call term_wait(buf)
 
   " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight
   call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
index 3116b803f14e74ec678121da45d5cac21b35d345..853c69c306bd00b92fb5bcb274ef7f789dbe2327 100644 (file)
@@ -806,3 +806,26 @@ func Test_terminal_term_start_empty_command()
   let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})"
   call assert_fails(cmd, 'E474')
 endfunc
+
+func Test_terminal_response_to_control_sequence()
+  if !has('unix')
+    return
+  endif
+
+  let buf = Run_shell_in_terminal({})
+  call term_wait(buf)
+
+  call term_sendkeys(buf, s:python . " -c 'import sys;sys.stdout.write(\"\\x1b[6n\")'\<cr>")
+  " wait for the response of control sequence from libvterm (and send it to tty)
+  call term_wait(buf, 100)
+  " wait for output from tty to display
+  call term_wait(buf)
+  call assert_match(';\d\+R', term_getline(buf, 2))
+
+  call term_sendkeys(buf, "\<c-c>")
+  call term_wait(buf)
+  call Stop_shell_in_terminal(buf)
+
+  exe buf . 'bwipe'
+  unlet g:job
+endfunc
index 09fb3005693ea3566fae7a7e207406ce572ca0f9..282f662a9db1e111291ed5ac81b0653d910ad88f 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1440,
 /**/
     1439,
 /**/