Patch 8.0.1036
Problem:    ++eof argument for terminal only available on MS-Windows.
Solution:   Also support ++eof on Unix.  Add a test.
Files:      src/channel.c, src/terminal.c, src/structs.h,
            src/testdir/test_terminal.vim


*** ../vim-8.0.1035/src/channel.c       2017-09-02 16:28:32.994776598 +0200
--- src/channel.c       2017-09-02 17:04:03.724664080 +0200
***************
*** 1422,1430 ****
      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
--- 1422,1429 ----
      in_part->ch_buf_top = lnum;
      if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot)
      {
! #if defined(FEAT_TERMINAL)
!       /* Send CTRL-D or "eof_chars" to close stdin on MS-Windows. */
        if (channel->ch_job != NULL)
            term_send_eof(channel);
  #endif
***************
*** 4640,4646 ****
            }
            else if (STRCMP(hi->hi_key, "eof_chars") == 0)
            {
- # ifdef WIN3264
                char_u *p;
  
                if (!(supported2 & JO2_EOF_CHARS))
--- 4639,4644 ----
***************
*** 4652,4658 ****
                    EMSG2(_(e_invarg2), "term_opencmd");
                    return FAIL;
                }
- # endif
            }
            else if (STRCMP(hi->hi_key, "term_rows") == 0)
            {
--- 4650,4655 ----
*** ../vim-8.0.1035/src/terminal.c      2017-09-02 16:28:32.994776598 +0200
--- src/terminal.c      2017-09-02 17:04:20.384554524 +0200
***************
*** 110,120 ****
      int               tl_channel_closed;
      int               tl_finish;      /* 'c' for ++close, 'o' for ++open */
      char_u    *tl_opencmd;
  
  #ifdef WIN3264
      void      *tl_winpty_config;
      void      *tl_winpty;
-     char_u    *tl_eof_chars;
  #endif
  
      /* last known vterm size */
--- 110,120 ----
      int               tl_channel_closed;
      int               tl_finish;      /* 'c' for ++close, 'o' for ++open */
      char_u    *tl_opencmd;
+     char_u    *tl_eof_chars;
  
  #ifdef WIN3264
      void      *tl_winpty_config;
      void      *tl_winpty;
  #endif
  
      /* last known vterm size */
***************
*** 390,399 ****
      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);
--- 390,397 ----
***************
*** 499,505 ****
        else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
                                                                 && ep != NULL)
        {
- # ifdef WIN3264
            char_u *buf = NULL;
            char_u *keys;
  
--- 497,502 ----
***************
*** 510,518 ****
            opt.jo_eof_chars = vim_strsave(keys);
            vim_free(buf);
            *p = ' ';
- # else
-           p = skiptowhite(cmd);
- # endif
        }
        else
        {
--- 507,512 ----
***************
*** 594,602 ****
      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;
--- 588,594 ----
***************
*** 2917,2922 ****
--- 2909,2940 ----
      }
  }
  
+ /*
+  * 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)
+       {
+           if (term->tl_eof_chars != NULL)
+           {
+               channel_send(ch, PART_IN, term->tl_eof_chars,
+                                       (int)STRLEN(term->tl_eof_chars), NULL);
+               channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
+           }
+ # ifdef WIN3264
+           else
+               /* Default: CTRL-D */
+               channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
+ # endif
+       }
+ }
+ 
  # if defined(WIN3264) || defined(PROTO)
  
  /**************************************
***************
*** 3216,3243 ****
      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)
-       {
-           if (term->tl_eof_chars != NULL)
-               channel_send(ch, PART_IN, term->tl_eof_chars,
-                                       (int)STRLEN(term->tl_eof_chars), NULL);
-           else
-               /* Default: CTRL-D */
-               channel_send(ch, PART_IN, (char_u *)"\004", 1, NULL);
-           channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
-       }
- }
- 
  # else
  
  /**************************************
--- 3234,3239 ----
*** ../vim-8.0.1035/src/structs.h       2017-09-02 16:28:32.994776598 +0200
--- src/structs.h       2017-09-02 17:04:28.756499469 +0200
***************
*** 1781,1789 ****
      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;
  
--- 1781,1787 ----
*** ../vim-8.0.1035/src/testdir/test_terminal.vim       2017-09-02 
14:54:16.384533128 +0200
--- src/testdir/test_terminal.vim       2017-09-02 17:14:17.120621849 +0200
***************
*** 490,513 ****
  
  func Test_terminal_write_stdin()
    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('$'))
    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('$'))
    call assert_equal(['2', '2', '10'], nrs)
    bwipe
  
    bwipe!
  endfunc
  
--- 490,536 ----
  
  func Test_terminal_write_stdin()
    if !executable('wc')
!     throw 'skipped: wc command not available'
    endif
    new
    call setline(1, ['one', 'two', 'three'])
    %term wc
!   call WaitFor('getline("$") =~ "3"')
    let nrs = split(getline('$'))
    call assert_equal(['3', '3', '14'], nrs)
    bwipe
  
+   new
    call setline(1, ['one', 'two', 'three', 'four'])
    2,3term wc
!   call WaitFor('getline("$") =~ "2"')
    let nrs = split(getline('$'))
    call assert_equal(['2', '2', '10'], nrs)
    bwipe
  
+   if executable('python')
+     new
+     call setline(1, ['print("hello")'])
+     1term ++eof=exit() python
+     " MS-Windows echoes the input, Unix doesn't.
+     call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"')
+     if getline(1) =~ 'hello'
+       call assert_equal('hello', getline(1))
+     else
+       call assert_equal('hello', getline(line('$') - 1))
+     endif
+     bwipe
+ 
+     if has('win32')
+       new
+       call setline(1, ['print("hello")'])
+       1term ++eof=<C-Z> python
+       call WaitFor('getline("$") =~ "Z"')
+       call assert_equal('hello', getline(line('$') - 1))
+       bwipe
+     endif
+   endif
+ 
    bwipe!
  endfunc
  
*** ../vim-8.0.1035/src/version.c       2017-09-02 16:28:33.002776544 +0200
--- src/version.c       2017-09-02 16:58:11.478983833 +0200
***************
*** 771,772 ****
--- 771,774 ----
  {   /* Add new patch number below this line */
+ /**/
+     1036,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
49. You never have to deal with busy signals when calling your ISP...because
    you never log off.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui