mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Problem: MS-Windows: job in terminal can't get back to Vim. Solution: set VIM_SERVERNAME in the environment. (Yasuhiro Matsumoto, closes #2360)
This commit is contained in:
parent
5505860152
commit
52dbb5ea7f
@ -1,4 +1,4 @@
|
|||||||
*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 12
|
*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 17
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -106,6 +106,10 @@ BufWinEnter autocommand event is triggered. This makes it possible to set
|
|||||||
options specifically for the window and buffer. Example: >
|
options specifically for the window and buffer. Example: >
|
||||||
au BufWinEnter * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
|
au BufWinEnter * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
|
||||||
|
|
||||||
|
Mouse events (click and drag) are passed to the terminal. Mouse move events
|
||||||
|
are only passed when Vim itself is receiving them. For a terminal that is
|
||||||
|
when 'balloonevalterm' is enabled.
|
||||||
|
|
||||||
|
|
||||||
Size and color ~
|
Size and color ~
|
||||||
*terminal-size-color*
|
*terminal-size-color*
|
||||||
@ -335,6 +339,9 @@ to point to the right file, if needed. If you have both the 32-bit and 64-bit
|
|||||||
version, rename to winpty32.dll and winpty64.dll to match the way Vim was
|
version, rename to winpty32.dll and winpty64.dll to match the way Vim was
|
||||||
build.
|
build.
|
||||||
|
|
||||||
|
Environment variables are used to pass information to the running job:
|
||||||
|
VIM_SERVERNAME v:servername
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
2. Remote testing *terminal-testing*
|
2. Remote testing *terminal-testing*
|
||||||
|
|
||||||
|
@ -5034,10 +5034,10 @@ job_io_file_open(
|
|||||||
* environment argument of vim_create_process().
|
* environment argument of vim_create_process().
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
win32_build_env(dict_T *env, garray_T *gap)
|
win32_build_env(dict_T *env, garray_T *gap, int is_terminal)
|
||||||
{
|
{
|
||||||
hashitem_T *hi;
|
hashitem_T *hi;
|
||||||
int todo = (int)env->dv_hashtab.ht_used;
|
long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0;
|
||||||
LPVOID base = GetEnvironmentStringsW();
|
LPVOID base = GetEnvironmentStringsW();
|
||||||
|
|
||||||
/* for last \0 */
|
/* for last \0 */
|
||||||
@ -5062,35 +5062,56 @@ win32_build_env(dict_T *env, garray_T *gap)
|
|||||||
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
|
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (hi = env->dv_hashtab.ht_array; todo > 0; ++hi)
|
if (env != NULL)
|
||||||
{
|
{
|
||||||
if (!HASHITEM_EMPTY(hi))
|
for (hi = env->dv_hashtab.ht_array; todo > 0; ++hi)
|
||||||
{
|
{
|
||||||
typval_T *item = &dict_lookup(hi)->di_tv;
|
if (!HASHITEM_EMPTY(hi))
|
||||||
WCHAR *wkey = enc_to_utf16((char_u *)hi->hi_key, NULL);
|
|
||||||
WCHAR *wval = enc_to_utf16(get_tv_string(item), NULL);
|
|
||||||
--todo;
|
|
||||||
if (wkey != NULL && wval != NULL)
|
|
||||||
{
|
{
|
||||||
size_t n;
|
typval_T *item = &dict_lookup(hi)->di_tv;
|
||||||
size_t lkey = wcslen(wkey);
|
WCHAR *wkey = enc_to_utf16((char_u *)hi->hi_key, NULL);
|
||||||
size_t lval = wcslen(wval);
|
WCHAR *wval = enc_to_utf16(get_tv_string(item), NULL);
|
||||||
|
--todo;
|
||||||
|
if (wkey != NULL && wval != NULL)
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
size_t lkey = wcslen(wkey);
|
||||||
|
size_t lval = wcslen(wval);
|
||||||
|
|
||||||
if (ga_grow(gap, (int)(lkey + lval + 2)) != OK)
|
if (ga_grow(gap, (int)(lkey + lval + 2)) != OK)
|
||||||
continue;
|
continue;
|
||||||
for (n = 0; n < lkey; n++)
|
for (n = 0; n < lkey; n++)
|
||||||
*((WCHAR*)gap->ga_data + gap->ga_len++) = wkey[n];
|
*((WCHAR*)gap->ga_data + gap->ga_len++) = wkey[n];
|
||||||
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'=';
|
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'=';
|
||||||
for (n = 0; n < lval; n++)
|
for (n = 0; n < lval; n++)
|
||||||
*((WCHAR*)gap->ga_data + gap->ga_len++) = wval[n];
|
*((WCHAR*)gap->ga_data + gap->ga_len++) = wval[n];
|
||||||
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
|
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
|
||||||
|
}
|
||||||
|
if (wkey != NULL) vim_free(wkey);
|
||||||
|
if (wval != NULL) vim_free(wval);
|
||||||
}
|
}
|
||||||
if (wkey != NULL) vim_free(wkey);
|
|
||||||
if (wval != NULL) vim_free(wval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
|
# ifdef FEAT_CLIENTSERVER
|
||||||
|
if (is_terminal)
|
||||||
|
{
|
||||||
|
char_u *servername = get_vim_var_str(VV_SEND_SERVER);
|
||||||
|
size_t lval = STRLEN(servername);
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
if (ga_grow(gap, (int)(14 + lval + 2)) == OK)
|
||||||
|
{
|
||||||
|
for (n = 0; n < 15; n++)
|
||||||
|
*((WCHAR*)gap->ga_data + gap->ga_len++) =
|
||||||
|
(WCHAR)"VIM_SERVERNAME="[n];
|
||||||
|
for (n = 0; n < lval; n++)
|
||||||
|
*((WCHAR*)gap->ga_data + gap->ga_len++) =
|
||||||
|
(WCHAR)servername[n];
|
||||||
|
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -5133,7 +5154,7 @@ mch_job_start(char *cmd, job_T *job, jobopt_T *options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options->jo_env != NULL)
|
if (options->jo_env != NULL)
|
||||||
win32_build_env(options->jo_env, &ga);
|
win32_build_env(options->jo_env, &ga, FALSE);
|
||||||
|
|
||||||
ZeroMemory(&pi, sizeof(pi));
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
ZeroMemory(&si, sizeof(si));
|
ZeroMemory(&si, sizeof(si));
|
||||||
|
@ -67,5 +67,5 @@ void used_file_arg(char *name, int literal, int full_path, int diff_mode);
|
|||||||
void set_alist_count(void);
|
void set_alist_count(void);
|
||||||
void fix_arg_enc(void);
|
void fix_arg_enc(void);
|
||||||
int mch_setenv(char *var, char *value, int x);
|
int mch_setenv(char *var, char *value, int x);
|
||||||
void win32_build_env(dict_T *l, garray_T *gap);
|
void win32_build_env(dict_T *l, garray_T *gap, int is_terminal);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@ -3424,12 +3424,10 @@ term_and_job_init(
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
if (opt->jo_cwd != NULL)
|
if (opt->jo_cwd != NULL)
|
||||||
cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
|
cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
|
||||||
if (opt->jo_env != NULL)
|
|
||||||
{
|
ga_init2(&ga_env, (int)sizeof(char*), 20);
|
||||||
ga_init2(&ga_env, (int)sizeof(char*), 20);
|
win32_build_env(opt->jo_env, &ga_env, TRUE);
|
||||||
win32_build_env(opt->jo_env, &ga_env);
|
env_wchar = ga_env.ga_data;
|
||||||
env_wchar = ga_env.ga_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
job = job_alloc();
|
job = job_alloc();
|
||||||
if (job == NULL)
|
if (job == NULL)
|
||||||
@ -3531,8 +3529,7 @@ term_and_job_init(
|
|||||||
failed:
|
failed:
|
||||||
if (argvar->v_type == VAR_LIST)
|
if (argvar->v_type == VAR_LIST)
|
||||||
vim_free(ga_cmd.ga_data);
|
vim_free(ga_cmd.ga_data);
|
||||||
if (opt->jo_env != NULL)
|
vim_free(ga_env.ga_data);
|
||||||
vim_free(ga_env.ga_data);
|
|
||||||
vim_free(cmd_wchar);
|
vim_free(cmd_wchar);
|
||||||
vim_free(cwd_wchar);
|
vim_free(cwd_wchar);
|
||||||
if (spawn_config != NULL)
|
if (spawn_config != NULL)
|
||||||
|
@ -434,6 +434,27 @@ func Test_terminal_cwd()
|
|||||||
call delete('Xdir', 'rf')
|
call delete('Xdir', 'rf')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_terminal_servername()
|
||||||
|
if !has('clientserver')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let g:buf = Run_shell_in_terminal({})
|
||||||
|
" Wait for the shell to display a prompt
|
||||||
|
call WaitFor('term_getline(g:buf, 1) != ""')
|
||||||
|
if has('win32')
|
||||||
|
call term_sendkeys(g:buf, "echo %VIM_SERVERNAME%\r")
|
||||||
|
else
|
||||||
|
call term_sendkeys(g:buf, "echo $VIM_SERVERNAME\r")
|
||||||
|
endif
|
||||||
|
call term_wait(g:buf)
|
||||||
|
call Stop_shell_in_terminal(g:buf)
|
||||||
|
call WaitFor('getline(2) == v:servername')
|
||||||
|
call assert_equal(v:servername, getline(2))
|
||||||
|
|
||||||
|
exe g:buf . 'bwipe'
|
||||||
|
unlet g:buf
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_terminal_env()
|
func Test_terminal_env()
|
||||||
let g:buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
|
let g:buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
|
||||||
" Wait for the shell to display a prompt
|
" Wait for the shell to display a prompt
|
||||||
|
@ -771,6 +771,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 */
|
||||||
|
/**/
|
||||||
|
1330,
|
||||||
/**/
|
/**/
|
||||||
1329,
|
1329,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user