3939 *
4040 * TODO:
4141 * - ":term NONE" does not work in MS-Windows.
42- * - test for writing lines to terminal job does not work on MS-Windows
4342 * - implement term_setsize()
4443 * - add test for giving error for invalid 'termsize' value.
4544 * - support minimal size when 'termsize' is "rows*cols".
4847 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save
4948 * changes to "!shell".
5049 * (justrajdeep, 2017 Aug 22)
51- * - command argument with spaces doesn't work #1999
52- * :terminal ls dir\ with\ spaces
53- * - implement job options when starting a terminal. Allow:
54- * "in_io", "in_top", "in_bot", "in_name", "in_buf"
55- "out_io", "out_name", "out_buf", "out_modifiable", "out_msg"
56- "err_io", "err_name", "err_buf", "err_modifiable", "err_msg"
57- * Check that something is connected to the terminal.
58- * Test: "cat" reading from a file or buffer
59- * "ls" writing stdout to a file or buffer
60- * shell writing stderr to a file or buffer
6150 * - For the GUI fill termios with default values, perhaps like pangoterm:
6251 * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
6352 * - if the job in the terminal does not support the mouse, we can use the
@@ -219,16 +208,6 @@ init_job_options(jobopt_T *opt)
219208 opt -> jo_out_mode = MODE_RAW ;
220209 opt -> jo_err_mode = MODE_RAW ;
221210 opt -> jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE ;
222-
223- opt -> jo_io [PART_OUT ] = JIO_BUFFER ;
224- opt -> jo_io [PART_ERR ] = JIO_BUFFER ;
225- opt -> jo_set |= JO_OUT_IO + JO_ERR_IO ;
226-
227- opt -> jo_modifiable [PART_OUT ] = 0 ;
228- opt -> jo_modifiable [PART_ERR ] = 0 ;
229- opt -> jo_set |= JO_OUT_MODIFIABLE + JO_ERR_MODIFIABLE ;
230-
231- opt -> jo_set |= JO_OUT_BUF + JO_ERR_BUF ;
232211}
233212
234213/*
@@ -237,8 +216,24 @@ init_job_options(jobopt_T *opt)
237216 static void
238217setup_job_options (jobopt_T * opt , int rows , int cols )
239218{
240- opt -> jo_io_buf [PART_OUT ] = curbuf -> b_fnum ;
241- opt -> jo_io_buf [PART_ERR ] = curbuf -> b_fnum ;
219+ if (!(opt -> jo_set & JO_OUT_IO ))
220+ {
221+ /* Connect stdout to the terminal. */
222+ opt -> jo_io [PART_OUT ] = JIO_BUFFER ;
223+ opt -> jo_io_buf [PART_OUT ] = curbuf -> b_fnum ;
224+ opt -> jo_modifiable [PART_OUT ] = 0 ;
225+ opt -> jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE ;
226+ }
227+
228+ if (!(opt -> jo_set & JO_ERR_IO ))
229+ {
230+ /* Connect stderr to the terminal. */
231+ opt -> jo_io [PART_ERR ] = JIO_BUFFER ;
232+ opt -> jo_io_buf [PART_ERR ] = curbuf -> b_fnum ;
233+ opt -> jo_modifiable [PART_ERR ] = 0 ;
234+ opt -> jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE ;
235+ }
236+
242237 opt -> jo_pty = TRUE;
243238 if ((opt -> jo_set2 & JO2_TERM_ROWS ) == 0 )
244239 opt -> jo_term_rows = rows ;
@@ -258,6 +253,15 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
258253 if (check_restricted () || check_secure ())
259254 return ;
260255
256+ if ((opt -> jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO ))
257+ == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO )
258+ || (!(opt -> jo_set & JO_OUT_IO ) && (opt -> jo_set & JO_OUT_BUF ))
259+ || (!(opt -> jo_set & JO_ERR_IO ) && (opt -> jo_set & JO_ERR_BUF )))
260+ {
261+ EMSG (_ (e_invarg ));
262+ return ;
263+ }
264+
261265 term = (term_T * )alloc_clear (sizeof (term_T ));
262266 if (term == NULL )
263267 return ;
@@ -2833,11 +2837,10 @@ f_term_start(typval_T *argvars, typval_T *rettv)
28332837 jobopt_T opt ;
28342838
28352839 init_job_options (& opt );
2836- /* TODO: allow more job options */
28372840 if (argvars [1 ].v_type != VAR_UNKNOWN
28382841 && get_job_options (& argvars [1 ], & opt ,
28392842 JO_TIMEOUT_ALL + JO_STOPONEXIT
2840- + JO_EXIT_CB + JO_CLOSE_CALLBACK ,
2843+ + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO ,
28412844 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
28422845 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
28432846 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS ) == FAIL )
@@ -3254,7 +3257,6 @@ term_and_job_init(
32543257{
32553258 create_vterm (term , term -> tl_rows , term -> tl_cols );
32563259
3257- /* TODO: if the command is "NONE" only create a pty. */
32583260 term -> tl_job = job_start (argvar , opt );
32593261 if (term -> tl_job != NULL )
32603262 ++ term -> tl_job -> jv_refcount ;
0 commit comments