summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-03-18 19:29:34 +0100
committerBram Moolenaar <Bram@vim.org>2018-03-18 19:29:34 +0100
commitf05fa378229004fb64493b411b864709ce7da453 (patch)
tree2eccbf5ccf68ca3afcb159c712267cfb1ead00dd
parent52acb110ac025b57dad5f5ec6004abbe4726a718 (diff)
patch 8.0.1616: Win32: shell commands in the GUI open a new consolev8.0.1616
Problem: Win32: shell commands in the GUI open a new console. Solution: Use a terminal window for interactive use when 'guioptions' contains "!".
-rw-r--r--src/os_win32.c78
-rw-r--r--src/version.c2
2 files changed, 79 insertions, 1 deletions
diff --git a/src/os_win32.c b/src/os_win32.c
index 0199996a86..c3f3f687e3 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -4488,7 +4488,7 @@ mch_system_piped(char *cmd, int options)
int c;
int noread_cnt = 0;
garray_T ga;
- int delay = 1;
+ int delay = 1;
DWORD buffer_off = 0; /* valid bytes in buffer[] */
char *p = NULL;
@@ -4782,6 +4782,69 @@ mch_system(char *cmd, int options)
#endif
+#if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
+/*
+ * Use a terminal window to run a shell command in.
+ */
+ static int
+mch_call_shell_terminal(
+ char_u *cmd,
+ int options UNUSED) /* SHELL_*, see vim.h */
+{
+ jobopt_T opt;
+ char_u *newcmd = NULL;
+ typval_T argvar[2];
+ long_u cmdlen;
+ int retval = -1;
+ buf_T *buf;
+ aco_save_T aco;
+ oparg_T oa; /* operator arguments */
+
+ cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
+
+ newcmd = lalloc(cmdlen, TRUE);
+ if (newcmd == NULL)
+ return 255;
+ vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd);
+
+ init_job_options(&opt);
+ ch_log(NULL, "starting terminal for system command '%s'", cmd);
+
+ argvar[0].v_type = VAR_STRING;
+ argvar[0].vval.v_string = newcmd;
+ argvar[1].v_type = VAR_UNKNOWN;
+ buf = term_start(argvar, NULL, &opt, TERM_START_SYSTEM);
+
+ /* Find a window to make "buf" curbuf. */
+ aucmd_prepbuf(&aco, buf);
+
+ clear_oparg(&oa);
+ while (term_use_loop())
+ {
+ if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active)
+ {
+ /* If terminal_loop() returns OK we got a key that is handled
+ * in Normal model. We don't do redrawing anyway. */
+ if (terminal_loop(TRUE) == OK)
+ normal_cmd(&oa, TRUE);
+ }
+ else
+ normal_cmd(&oa, TRUE);
+ }
+ retval = 0;
+ ch_log(NULL, "system command finished");
+
+ /* restore curwin/curbuf and a few other things */
+ aucmd_restbuf(&aco);
+
+ wait_return(TRUE);
+ do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
+
+ vim_free(newcmd);
+ return retval;
+}
+#endif
+
/*
* Either execute a command by calling the shell or start a new shell
*/
@@ -4851,6 +4914,19 @@ mch_call_shell(
fflush(fdDump);
}
#endif
+#if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
+ /* TODO: make the terminal window work with input or output redirected. */
+ if (vim_strchr(p_go, GO_TERMINAL) != NULL
+ && (options & (SHELL_FILTER|SHELL_DOOUT|SHELL_WRITE|SHELL_READ)) == 0)
+ {
+ /* Use a terminal window to run the command in. */
+ x = mch_call_shell_terminal(cmd, options);
+#ifdef FEAT_TITLE
+ resettitle();
+#endif
+ return x;
+ }
+#endif
/*
* Catch all deadly signals while running the external command, because a
diff --git a/src/version.c b/src/version.c
index 6beb36e414..58c4e89848 100644
--- a/src/version.c
+++ b/src/version.c
@@ -767,6 +767,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1616,
+/**/
1615,
/**/
1614,