Skip to content

Commit ba6febd

Browse files
committed
patch 8.0.1240: MS-Windows: term_start() does not support environment
Problem: MS-Windows: term_start() does not support environment. Solution: Implement the environment argument. (Yasuhiro Matsumoto, closes #2264)
1 parent 4857048 commit ba6febd

5 files changed

Lines changed: 40 additions & 14 deletions

File tree

src/os_win32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,8 +5033,8 @@ job_io_file_open(
50335033
* Turn the dictionary "env" into a NUL separated list that can be used as the
50345034
* environment argument of vim_create_process().
50355035
*/
5036-
static void
5037-
make_job_env(garray_T *gap, dict_T *env)
5036+
void
5037+
win32_build_env(dict_T *env, garray_T *gap)
50385038
{
50395039
hashitem_T *hi;
50405040
int todo = (int)env->dv_hashtab.ht_used;
@@ -5133,7 +5133,7 @@ mch_job_start(char *cmd, job_T *job, jobopt_T *options)
51335133
}
51345134

51355135
if (options->jo_env != NULL)
5136-
make_job_env(&ga, options->jo_env);
5136+
win32_build_env(options->jo_env, &ga);
51375137

51385138
ZeroMemory(&pi, sizeof(pi));
51395139
ZeroMemory(&si, sizeof(si));

src/proto/os_win32.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ void used_file_arg(char *name, int literal, int full_path, int diff_mode);
6767
void set_alist_count(void);
6868
void fix_arg_enc(void);
6969
int mch_setenv(char *var, char *value, int x);
70+
void win32_build_env(dict_T *l, garray_T *gap);
7071
/* vim: set ft=c : */

src/terminal.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@
4646
* - Redirecting output does not work on MS-Windows, Test_terminal_redir_file()
4747
* is disabled.
4848
* - cursor blinks in terminal on widows with a timer. (xtal8, #2142)
49+
* - When closing gvim with an active terminal buffer, the dialog suggests
50+
* saving the buffer. Should say something else. (Manas Thakur, #2215)
51+
* Also: #2223
4952
* - implement term_setsize()
53+
* - Termdebug does not work when Vim build with mzscheme. gdb hangs.
54+
* - Termdebug: issue #2154 might be avoided by adding -quiet to gdb?
55+
* patch by Christian, 2017 Oct 23.
5056
* - MS-Windows GUI: WinBar has tearoff item
5157
* - MS-Windows GUI: still need to type a key after shell exits? #1924
58+
* - What to store in a session file? Shell at the prompt would be OK to
59+
* restore, but others may not. Open the window and let the user start the
60+
* command?
5261
* - add test for giving error for invalid 'termsize' value.
5362
* - support minimal size when 'termsize' is "rows*cols".
5463
* - support minimal size when 'termsize' is empty?
@@ -3390,6 +3399,7 @@ term_and_job_init(
33903399
{
33913400
WCHAR *cmd_wchar = NULL;
33923401
WCHAR *cwd_wchar = NULL;
3402+
WCHAR *env_wchar = NULL;
33933403
channel_T *channel = NULL;
33943404
job_T *job = NULL;
33953405
DWORD error;
@@ -3398,7 +3408,7 @@ term_and_job_init(
33983408
HANDLE child_thread_handle;
33993409
void *winpty_err;
34003410
void *spawn_config = NULL;
3401-
garray_T ga;
3411+
garray_T ga_cmd, ga_env;
34023412
char_u *cmd;
34033413

34043414
if (dyn_winpty_init(TRUE) == FAIL)
@@ -3408,17 +3418,23 @@ term_and_job_init(
34083418
cmd = argvar->vval.v_string;
34093419
else
34103420
{
3411-
ga_init2(&ga, (int)sizeof(char*), 20);
3412-
if (win32_build_cmd(argvar->vval.v_list, &ga) == FAIL)
3421+
ga_init2(&ga_cmd, (int)sizeof(char*), 20);
3422+
if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
34133423
goto failed;
3414-
cmd = ga.ga_data;
3424+
cmd = ga_cmd.ga_data;
34153425
}
34163426

34173427
cmd_wchar = enc_to_utf16(cmd, NULL);
34183428
if (cmd_wchar == NULL)
34193429
return FAIL;
34203430
if (opt->jo_cwd != NULL)
34213431
cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
3432+
if (opt->jo_env != NULL)
3433+
{
3434+
ga_init2(&ga_env, (int)sizeof(char*), 20);
3435+
win32_build_env(opt->jo_env, &ga_env);
3436+
env_wchar = ga_env.ga_data;
3437+
}
34223438

34233439
job = job_alloc();
34243440
if (job == NULL)
@@ -3446,7 +3462,7 @@ term_and_job_init(
34463462
NULL,
34473463
cmd_wchar,
34483464
cwd_wchar,
3449-
NULL,
3465+
env_wchar,
34503466
&winpty_err);
34513467
if (spawn_config == NULL)
34523468
goto failed;
@@ -3519,7 +3535,9 @@ term_and_job_init(
35193535

35203536
failed:
35213537
if (argvar->v_type == VAR_LIST)
3522-
vim_free(ga.ga_data);
3538+
vim_free(ga_cmd.ga_data);
3539+
if (opt->jo_env != NULL)
3540+
vim_free(ga_env.ga_data);
35233541
vim_free(cmd_wchar);
35243542
vim_free(cwd_wchar);
35253543
if (spawn_config != NULL)

src/testdir/test_terminal.vim

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ let s:python = PythonProg()
1111
" Open a terminal with a shell, assign the job to g:job and return the buffer
1212
" number.
1313
func Run_shell_in_terminal(options)
14-
let buf = term_start(&shell, a:options)
14+
if has('win32')
15+
let buf = term_start([&shell,'/k'], a:options)
16+
else
17+
let buf = term_start(&shell, a:options)
18+
endif
1519

1620
let termlist = term_list()
1721
call assert_equal(1, len(termlist))
@@ -430,13 +434,14 @@ func Test_terminal_cwd()
430434
endfunc
431435

432436
func Test_terminal_env()
433-
if !has('unix')
434-
return
435-
endif
436437
let g:buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
437438
" Wait for the shell to display a prompt
438439
call WaitFor('term_getline(g:buf, 1) != ""')
439-
call term_sendkeys(g:buf, "echo $TESTENV\r")
440+
if has('win32')
441+
call term_sendkeys(g:buf, "echo %TESTENV%\r")
442+
else
443+
call term_sendkeys(g:buf, "echo $TESTENV\r")
444+
endif
440445
call term_wait(g:buf)
441446
call Stop_shell_in_terminal(g:buf)
442447
call WaitFor('getline(2) == "correct"')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1240,
764766
/**/
765767
1239,
766768
/**/

0 commit comments

Comments
 (0)