@@ -4488,7 +4488,7 @@ mch_system_piped(char *cmd, int options)
4488
4488
int c ;
4489
4489
int noread_cnt = 0 ;
4490
4490
garray_T ga ;
4491
- int delay = 1 ;
4491
+ int delay = 1 ;
4492
4492
DWORD buffer_off = 0 ; /* valid bytes in buffer[] */
4493
4493
char * p = NULL ;
4494
4494
@@ -4782,6 +4782,69 @@ mch_system(char *cmd, int options)
4782
4782
4783
4783
#endif
4784
4784
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
+
4785
4848
/*
4786
4849
* Either execute a command by calling the shell or start a new shell
4787
4850
*/
@@ -4851,6 +4914,19 @@ mch_call_shell(
4851
4914
fflush (fdDump );
4852
4915
}
4853
4916
#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
4854
4930
4855
4931
/*
4856
4932
* Catch all deadly signals while running the external command, because a
0 commit comments