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.
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");
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))
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);
#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 \
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;
#ifdef WIN3264
void *tl_winpty_config;
void *tl_winpty;
+ char_u *tl_eof_chars;
#endif
/* last known vterm size */
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);
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;
+ 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)
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
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1034,
/**/
1033,
/**/