]> granicus.if.org Git - vim/commitdiff
patch 8.0.1034: sending buffer lines to terminal doesn't work on MS-Windows v8.0.1034
authorBram Moolenaar <Bram@vim.org>
Sat, 2 Sep 2017 12:54:21 +0000 (14:54 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 2 Sep 2017 12:54:21 +0000 (14:54 +0200)
Problem:    Sending buffer lines to terminal doesn't work on MS-Windows.
Solution:   Send CTRL-D to mark the end of the text. (Yasuhiro Matsumoto,
            closes #2043) Add the "eof_chars" option.

src/channel.c
src/proto/terminal.pro
src/structs.h
src/terminal.c
src/testdir/test_terminal.vim
src/version.c

index b7a268a79a8bdf2614403fec7d486da7751cc074..94a762c6106d03a23e5de86a9937397b20e0effa 100644 (file)
@@ -1417,6 +1417,13 @@ channel_write_in(channel_T *channel)
     in_part->ch_buf_top = lnum;
     if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot)
     {
+#if defined(WIN32) && defined(FEAT_TERMINAL)
+       /* Send CTRL-D or "eof_chars" to close stdin on Windows. A console
+        * application doesn't treat closing stdin like UNIX. */
+       if (channel->ch_job != NULL)
+           term_send_eof(channel);
+#endif
+
        /* Writing is done, no longer need the buffer. */
        in_part->ch_bufref.br_buf = NULL;
        ch_log(channel, "Finished writing all lines to channel");
@@ -4626,6 +4633,22 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
                    return FAIL;
                }
            }
+           else if (STRCMP(hi->hi_key, "eof_chars") == 0)
+           {
+# ifdef WIN3264
+               char_u *p;
+
+               if (!(supported2 & JO2_EOF_CHARS))
+                   break;
+               opt->jo_set2 |= JO2_EOF_CHARS;
+               p = opt->jo_eof_chars = get_tv_string_chk(item);
+               if (p == NULL)
+               {
+                   EMSG2(_(e_invarg2), "term_opencmd");
+                   return FAIL;
+               }
+# endif
+           }
            else if (STRCMP(hi->hi_key, "term_rows") == 0)
            {
                if (!(supported2 & JO2_TERM_ROWS))
index 2b05d341e2a2f208f823171c899227c5e6370f9a..3811ba7a51d45c0131657f3ca83491a957460293 100644 (file)
@@ -16,6 +16,7 @@ int term_update_window(win_T *wp);
 int term_is_finished(buf_T *buf);
 int term_show_buffer(buf_T *buf);
 void term_change_in_curbuf(void);
+void term_send_eof(channel_T *ch);
 int term_get_attr(buf_T *buf, linenr_T lnum, int col);
 char_u *term_get_status_text(term_T *term);
 int set_ref_in_term(int copyID);
index 4030f6d51fb16d35f9e42c732e6e56eaa1086617..20b7ef80570d4b8c8adc01e576c5e966570be1e4 100644 (file)
@@ -1713,7 +1713,8 @@ struct channel_S {
 #define JO2_CURWIN         0x0200      /* "curwin" */
 #define JO2_HIDDEN         0x0400      /* "hidden" */
 #define JO2_TERM_OPENCMD    0x0800     /* "term_opencmd" */
-#define JO2_ALL                    0x0FFF
+#define JO2_EOF_CHARS      0x1000      /* "eof_chars" */
+#define JO2_ALL                    0x1FFF
 
 #define JO_MODE_ALL    (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
 #define JO_CB_ALL \
@@ -1779,6 +1780,9 @@ typedef struct
     char_u     *jo_term_name;
     char_u     *jo_term_opencmd;
     int                jo_term_finish;
+# ifdef WIN3264
+    char_u     *jo_eof_chars;
+# endif
 #endif
 } jobopt_T;
 
index 8d6fdb8e03118817eb1a4a50a263d6b5090b1dd0..0a3e1b71f0ac23dc4b02119c7901237f17577753 100644 (file)
@@ -114,6 +114,7 @@ struct terminal_S {
 #ifdef WIN3264
     void       *tl_winpty_config;
     void       *tl_winpty;
+    char_u     *tl_eof_chars;
 #endif
 
     /* last known vterm size */
@@ -389,6 +390,11 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
     if (opt->jo_term_opencmd != NULL)
        term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
 
+# ifdef WIN3264
+    if (opt->jo_eof_chars != NULL)
+       term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
+# endif
+
     set_string_option_direct((char_u *)"buftype", -1,
                                  (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
 
@@ -570,6 +576,9 @@ free_terminal(buf_T *buf)
     vim_free(term->tl_title);
     vim_free(term->tl_status_text);
     vim_free(term->tl_opencmd);
+# ifdef WIN3264
+    vim_free(term->tl_eof_chars);
+# endif
     vim_free(term->tl_cursor_color);
     vim_free(term);
     buf->b_term = NULL;
@@ -2821,7 +2830,7 @@ f_term_start(typval_T *argvars, typval_T *rettv)
                    + JO_EXIT_CB + JO_CLOSE_CALLBACK,
                JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
                    + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
-                   + JO2_CWD + JO2_ENV) == FAIL)
+                   + JO2_CWD + JO2_ENV + JO2_EOF_CHARS) == FAIL)
        return;
 
     if (opt.jo_vertical)
@@ -3188,6 +3197,20 @@ terminal_enabled(void)
     return dyn_winpty_init(FALSE) == OK;
 }
 
+/*
+ * Called when a channel has sent all the lines to a terminal.
+ * Send a CTRL-D to mark the end of the text.
+ */
+    void
+term_send_eof(channel_T *ch)
+{
+    term_T     *term;
+
+    for (term = first_term; term != NULL; term = term->tl_next)
+       if (term->tl_job == ch->ch_job)
+           channel_send(ch, PART_IN, term->tl_eof_chars != NULL
+                        ? term->tl_eof_chars : (char_u *)"\004\r\n", 3, NULL);
+}
 
 # else
 
index b6c926f4019034b237db18273b1d856c84edeccb..573db1e01de083b26e92cd09cc061f6ba33f109c 100644 (file)
@@ -489,22 +489,22 @@ func Test_terminal_noblock()
 endfunc
 
 func Test_terminal_write_stdin()
-  " Todo: make this work on all systems.
-  if !has('unix')
+  if !executable('wc')
+    call ch_log('Test_terminal_write_stdin() is skipped because system doesn''t have wc command')
     return
   endif
   new
   call setline(1, ['one', 'two', 'three'])
   %term wc
   call WaitFor('getline(1) != ""')
-  let nrs = split(getline(1))
+  let nrs = split(getline('$'))
   call assert_equal(['3', '3', '14'], nrs)
   bwipe
 
   call setline(1, ['one', 'two', 'three', 'four'])
   2,3term wc
   call WaitFor('getline(1) != ""')
-  let nrs = split(getline(1))
+  let nrs = split(getline('$'))
   call assert_equal(['2', '2', '10'], nrs)
   bwipe
 
index 807b2f1ab9e6b0cc1a0b70e1838f513d414e868d..b76c2a9d43c29d90ba8d3a1ac1258266b48f6d5c 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1034,
 /**/
     1033,
 /**/