To: vim_dev@googlegroups.com Subject: Patch 8.0.1616 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1616 Problem: Win32: shell commands in the GUI open a new console. Solution: Use a terminal window for interactive use when 'guioptions' contains "!". Files: src/os_win32.c *** ../vim-8.0.1615/src/os_win32.c 2018-03-08 22:03:09.867578790 +0100 --- src/os_win32.c 2018-03-18 19:27:13.059998149 +0100 *************** *** 4488,4494 **** int c; int noread_cnt = 0; garray_T ga; ! int delay = 1; DWORD buffer_off = 0; /* valid bytes in buffer[] */ char *p = NULL; --- 4488,4494 ---- int c; int noread_cnt = 0; garray_T ga; ! int delay = 1; DWORD buffer_off = 0; /* valid bytes in buffer[] */ char *p = NULL; *************** *** 4782,4787 **** --- 4782,4850 ---- #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,4856 **** --- 4914,4932 ---- 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 *** ../vim-8.0.1615/src/version.c 2018-03-18 19:19:33.266818628 +0100 --- src/version.c 2018-03-18 19:23:35.177321657 +0100 *************** *** 768,769 **** --- 768,771 ---- { /* Add new patch number below this line */ + /**/ + 1616, /**/ -- How To Keep A Healthy Level Of Insanity: 17. When the money comes out the ATM, scream "I won!, I won! 3rd time this week!!!!!" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///