mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.0.1036: ++eof argument for terminal only available on MS-Windows
Problem: ++eof argument for terminal only available on MS-Windows. Solution: Also support ++eof on Unix. Add a test.
This commit is contained in:
@@ -1422,9 +1422,8 @@ channel_write_in(channel_T *channel)
|
|||||||
in_part->ch_buf_top = lnum;
|
in_part->ch_buf_top = lnum;
|
||||||
if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot)
|
if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot)
|
||||||
{
|
{
|
||||||
#if defined(WIN32) && defined(FEAT_TERMINAL)
|
#if defined(FEAT_TERMINAL)
|
||||||
/* Send CTRL-D or "eof_chars" to close stdin on Windows. A console
|
/* Send CTRL-D or "eof_chars" to close stdin on MS-Windows. */
|
||||||
* application doesn't treat closing stdin like UNIX. */
|
|
||||||
if (channel->ch_job != NULL)
|
if (channel->ch_job != NULL)
|
||||||
term_send_eof(channel);
|
term_send_eof(channel);
|
||||||
#endif
|
#endif
|
||||||
@@ -4640,7 +4639,6 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
|
|||||||
}
|
}
|
||||||
else if (STRCMP(hi->hi_key, "eof_chars") == 0)
|
else if (STRCMP(hi->hi_key, "eof_chars") == 0)
|
||||||
{
|
{
|
||||||
# ifdef WIN3264
|
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
if (!(supported2 & JO2_EOF_CHARS))
|
if (!(supported2 & JO2_EOF_CHARS))
|
||||||
@@ -4652,7 +4650,6 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
|
|||||||
EMSG2(_(e_invarg2), "term_opencmd");
|
EMSG2(_(e_invarg2), "term_opencmd");
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
else if (STRCMP(hi->hi_key, "term_rows") == 0)
|
else if (STRCMP(hi->hi_key, "term_rows") == 0)
|
||||||
{
|
{
|
||||||
|
@@ -1781,9 +1781,7 @@ typedef struct
|
|||||||
char_u *jo_term_name;
|
char_u *jo_term_name;
|
||||||
char_u *jo_term_opencmd;
|
char_u *jo_term_opencmd;
|
||||||
int jo_term_finish;
|
int jo_term_finish;
|
||||||
# ifdef WIN3264
|
|
||||||
char_u *jo_eof_chars;
|
char_u *jo_eof_chars;
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
} jobopt_T;
|
} jobopt_T;
|
||||||
|
|
||||||
|
@@ -110,11 +110,11 @@ struct terminal_S {
|
|||||||
int tl_channel_closed;
|
int tl_channel_closed;
|
||||||
int tl_finish; /* 'c' for ++close, 'o' for ++open */
|
int tl_finish; /* 'c' for ++close, 'o' for ++open */
|
||||||
char_u *tl_opencmd;
|
char_u *tl_opencmd;
|
||||||
|
char_u *tl_eof_chars;
|
||||||
|
|
||||||
#ifdef WIN3264
|
#ifdef WIN3264
|
||||||
void *tl_winpty_config;
|
void *tl_winpty_config;
|
||||||
void *tl_winpty;
|
void *tl_winpty;
|
||||||
char_u *tl_eof_chars;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* last known vterm size */
|
/* last known vterm size */
|
||||||
@@ -390,10 +390,8 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
|
|||||||
if (opt->jo_term_opencmd != NULL)
|
if (opt->jo_term_opencmd != NULL)
|
||||||
term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
|
term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
|
||||||
|
|
||||||
# ifdef WIN3264
|
|
||||||
if (opt->jo_eof_chars != NULL)
|
if (opt->jo_eof_chars != NULL)
|
||||||
term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
|
term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
|
||||||
# endif
|
|
||||||
|
|
||||||
set_string_option_direct((char_u *)"buftype", -1,
|
set_string_option_direct((char_u *)"buftype", -1,
|
||||||
(char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
|
(char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
|
||||||
@@ -499,7 +497,6 @@ ex_terminal(exarg_T *eap)
|
|||||||
else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
|
else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
|
||||||
&& ep != NULL)
|
&& ep != NULL)
|
||||||
{
|
{
|
||||||
# ifdef WIN3264
|
|
||||||
char_u *buf = NULL;
|
char_u *buf = NULL;
|
||||||
char_u *keys;
|
char_u *keys;
|
||||||
|
|
||||||
@@ -510,9 +507,6 @@ ex_terminal(exarg_T *eap)
|
|||||||
opt.jo_eof_chars = vim_strsave(keys);
|
opt.jo_eof_chars = vim_strsave(keys);
|
||||||
vim_free(buf);
|
vim_free(buf);
|
||||||
*p = ' ';
|
*p = ' ';
|
||||||
# else
|
|
||||||
p = skiptowhite(cmd);
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -594,9 +588,7 @@ free_terminal(buf_T *buf)
|
|||||||
vim_free(term->tl_title);
|
vim_free(term->tl_title);
|
||||||
vim_free(term->tl_status_text);
|
vim_free(term->tl_status_text);
|
||||||
vim_free(term->tl_opencmd);
|
vim_free(term->tl_opencmd);
|
||||||
# ifdef WIN3264
|
|
||||||
vim_free(term->tl_eof_chars);
|
vim_free(term->tl_eof_chars);
|
||||||
# endif
|
|
||||||
vim_free(term->tl_cursor_color);
|
vim_free(term->tl_cursor_color);
|
||||||
vim_free(term);
|
vim_free(term);
|
||||||
buf->b_term = NULL;
|
buf->b_term = NULL;
|
||||||
@@ -2917,6 +2909,32 @@ f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
# if defined(WIN3264) || defined(PROTO)
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
@@ -3216,28 +3234,6 @@ terminal_enabled(void)
|
|||||||
return dyn_winpty_init(FALSE) == OK;
|
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
|
# else
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
|
@@ -490,24 +490,47 @@ endfunc
|
|||||||
|
|
||||||
func Test_terminal_write_stdin()
|
func Test_terminal_write_stdin()
|
||||||
if !executable('wc')
|
if !executable('wc')
|
||||||
call ch_log('Test_terminal_write_stdin() is skipped because system doesn''t have wc command')
|
throw 'skipped: wc command not available'
|
||||||
return
|
|
||||||
endif
|
endif
|
||||||
new
|
new
|
||||||
call setline(1, ['one', 'two', 'three'])
|
call setline(1, ['one', 'two', 'three'])
|
||||||
%term wc
|
%term wc
|
||||||
call WaitFor('getline(1) != ""')
|
call WaitFor('getline("$") =~ "3"')
|
||||||
let nrs = split(getline('$'))
|
let nrs = split(getline('$'))
|
||||||
call assert_equal(['3', '3', '14'], nrs)
|
call assert_equal(['3', '3', '14'], nrs)
|
||||||
bwipe
|
bwipe
|
||||||
|
|
||||||
|
new
|
||||||
call setline(1, ['one', 'two', 'three', 'four'])
|
call setline(1, ['one', 'two', 'three', 'four'])
|
||||||
2,3term wc
|
2,3term wc
|
||||||
call WaitFor('getline(1) != ""')
|
call WaitFor('getline("$") =~ "2"')
|
||||||
let nrs = split(getline('$'))
|
let nrs = split(getline('$'))
|
||||||
call assert_equal(['2', '2', '10'], nrs)
|
call assert_equal(['2', '2', '10'], nrs)
|
||||||
bwipe
|
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!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1036,
|
||||||
/**/
|
/**/
|
||||||
1035,
|
1035,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user