Skip to content

Commit f05fa37

Browse files
committed
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Problem: Win32: shell commands in the GUI open a new console. Solution: Use a terminal window for interactive use when 'guioptions' contains "!".
1 parent 52acb11 commit f05fa37

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/os_win32.c

+77-1
Original file line numberDiff line numberDiff line change
@@ -4488,7 +4488,7 @@ mch_system_piped(char *cmd, int options)
44884488
int c;
44894489
int noread_cnt = 0;
44904490
garray_T ga;
4491-
int delay = 1;
4491+
int delay = 1;
44924492
DWORD buffer_off = 0; /* valid bytes in buffer[] */
44934493
char *p = NULL;
44944494

@@ -4782,6 +4782,69 @@ mch_system(char *cmd, int options)
47824782

47834783
#endif
47844784

4785+
#if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
4786+
/*
4787+
* Use a terminal window to run a shell command in.
4788+
*/
4789+
static int
4790+
mch_call_shell_terminal(
4791+
char_u *cmd,
4792+
int options UNUSED) /* SHELL_*, see vim.h */
4793+
{
4794+
jobopt_T opt;
4795+
char_u *newcmd = NULL;
4796+
typval_T argvar[2];
4797+
long_u cmdlen;
4798+
int retval = -1;
4799+
buf_T *buf;
4800+
aco_save_T aco;
4801+
oparg_T oa; /* operator arguments */
4802+
4803+
cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
4804+
4805+
newcmd = lalloc(cmdlen, TRUE);
4806+
if (newcmd == NULL)
4807+
return 255;
4808+
vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd);
4809+
4810+
init_job_options(&opt);
4811+
ch_log(NULL, "starting terminal for system command '%s'", cmd);
4812+
4813+
argvar[0].v_type = VAR_STRING;
4814+
argvar[0].vval.v_string = newcmd;
4815+
argvar[1].v_type = VAR_UNKNOWN;
4816+
buf = term_start(argvar, NULL, &opt, TERM_START_SYSTEM);
4817+
4818+
/* Find a window to make "buf" curbuf. */
4819+
aucmd_prepbuf(&aco, buf);
4820+
4821+
clear_oparg(&oa);
4822+
while (term_use_loop())
4823+
{
4824+
if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active)
4825+
{
4826+
/* If terminal_loop() returns OK we got a key that is handled
4827+
* in Normal model. We don't do redrawing anyway. */
4828+
if (terminal_loop(TRUE) == OK)
4829+
normal_cmd(&oa, TRUE);
4830+
}
4831+
else
4832+
normal_cmd(&oa, TRUE);
4833+
}
4834+
retval = 0;
4835+
ch_log(NULL, "system command finished");
4836+
4837+
/* restore curwin/curbuf and a few other things */
4838+
aucmd_restbuf(&aco);
4839+
4840+
wait_return(TRUE);
4841+
do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
4842+
4843+
vim_free(newcmd);
4844+
return retval;
4845+
}
4846+
#endif
4847+
47854848
/*
47864849
* Either execute a command by calling the shell or start a new shell
47874850
*/
@@ -4851,6 +4914,19 @@ mch_call_shell(
48514914
fflush(fdDump);
48524915
}
48534916
#endif
4917+
#if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
4918+
/* TODO: make the terminal window work with input or output redirected. */
4919+
if (vim_strchr(p_go, GO_TERMINAL) != NULL
4920+
&& (options & (SHELL_FILTER|SHELL_DOOUT|SHELL_WRITE|SHELL_READ)) == 0)
4921+
{
4922+
/* Use a terminal window to run the command in. */
4923+
x = mch_call_shell_terminal(cmd, options);
4924+
#ifdef FEAT_TITLE
4925+
resettitle();
4926+
#endif
4927+
return x;
4928+
}
4929+
#endif
48544930

48554931
/*
48564932
* Catch all deadly signals while running the external command, because a

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ static char *(features[]) =
766766

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1616,
769771
/**/
770772
1615,
771773
/**/

0 commit comments

Comments
 (0)