Skip to content

Commit 08d384f

Browse files
committed
patch 8.0.0908: cannot set terminal size with options
Problem: Cannot set terminal size with options. Solution: Add "term_rows", "term_cols" and "vertical".
1 parent 89e06c8 commit 08d384f

8 files changed

Lines changed: 86 additions & 26 deletions

File tree

runtime/doc/eval.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8050,8 +8050,10 @@ term_sendkeys({buf}, {keys}) *term_sendkeys()*
80508050
term_start({cmd}, {options}) *term_start()*
80518051
Open a terminal window and run {cmd} in it.
80528052

8053-
Returns the buffer number of the terminal window.
8054-
When opening the window fails zero is returned.
8053+
Returns the buffer number of the terminal window. If {cmd}
8054+
cannot be executed the window does open and shows an error
8055+
message.
8056+
If opening the window fails zero is returned.
80558057

80568058
{options} are similar to what is used for |job_start()|, see
80578059
|job-options|. However, not all options can be used. These
@@ -8067,10 +8069,15 @@ term_start({cmd}, {options}) *term_start()*
80678069
connected to the terminal. When I/O is connected to the
80688070
terminal then the callback function for that part is not used.
80698071

8070-
There are two extra options:
8072+
There are extra options:
80718073
"term_name" name to use for the buffer name, instead
80728074
of the command name.
8073-
"term_finish" What todo when the job is finished:
8075+
"term_rows" vertical size to use for the terminal,
8076+
instead of using 'termsize'
8077+
"term_cols" horizontal size to use for the terminal,
8078+
instead of using 'termsize'
8079+
"vertical" split the window vertically
8080+
"term_finish" What to do when the job is finished:
80748081
"close": close any windows
80758082
"open": open window if needed
80768083
Note that "open" can be interruptive.

src/channel.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ channel_open_func(typval_T *argvars)
927927
opt.jo_mode = MODE_JSON;
928928
opt.jo_timeout = 2000;
929929
if (get_job_options(&argvars[1], &opt,
930-
JO_MODE_ALL + JO_CB_ALL + JO_WAITTIME + JO_TIMEOUT_ALL) == FAIL)
930+
JO_MODE_ALL + JO_CB_ALL + JO_WAITTIME + JO_TIMEOUT_ALL, 0) == FAIL)
931931
goto theend;
932932
if (opt.jo_timeout < 0)
933933
{
@@ -3429,7 +3429,7 @@ common_channel_read(typval_T *argvars, typval_T *rettv, int raw)
34293429
rettv->vval.v_string = NULL;
34303430

34313431
clear_job_options(&opt);
3432-
if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID)
3432+
if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID, 0)
34333433
== FAIL)
34343434
goto theend;
34353435

@@ -3612,7 +3612,7 @@ send_common(
36123612
part_send = channel_part_send(channel);
36133613
*part_read = channel_part_read(channel);
36143614

3615-
if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT) == FAIL)
3615+
if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT, 0) == FAIL)
36163616
return NULL;
36173617

36183618
/* Set the callback. An empty callback means no callback and not reading
@@ -4169,11 +4169,11 @@ part_from_char(int c)
41694169
/*
41704170
* Get the option entries from the dict in "tv", parse them and put the result
41714171
* in "opt".
4172-
* Only accept options in "supported".
4172+
* Only accept JO_ options in "supported" and JO2_ options in "supported2".
41734173
* If an option value is invalid return FAIL.
41744174
*/
41754175
int
4176-
get_job_options(typval_T *tv, jobopt_T *opt, int supported)
4176+
get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
41774177
{
41784178
typval_T *item;
41794179
char_u *val;
@@ -4411,7 +4411,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
44114411
#ifdef FEAT_TERMINAL
44124412
else if (STRCMP(hi->hi_key, "term_name") == 0)
44134413
{
4414-
if (!(supported & JO2_TERM_NAME))
4414+
if (!(supported2 & JO2_TERM_NAME))
44154415
break;
44164416
opt->jo_set2 |= JO2_TERM_NAME;
44174417
opt->jo_term_name = get_tv_string_chk(item);
@@ -4423,7 +4423,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
44234423
}
44244424
else if (STRCMP(hi->hi_key, "term_finish") == 0)
44254425
{
4426-
if (!(supported & JO2_TERM_FINISH))
4426+
if (!(supported2 & JO2_TERM_FINISH))
44274427
break;
44284428
val = get_tv_string(item);
44294429
if (STRCMP(val, "open") != 0 && STRCMP(val, "close") != 0)
@@ -4434,18 +4434,39 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
44344434
opt->jo_set2 |= JO2_TERM_FINISH;
44354435
opt->jo_term_finish = *val;
44364436
}
4437+
else if (STRCMP(hi->hi_key, "term_rows") == 0)
4438+
{
4439+
if (!(supported2 & JO2_TERM_ROWS))
4440+
break;
4441+
opt->jo_set |= JO2_TERM_ROWS;
4442+
opt->jo_term_rows = get_tv_number(item);
4443+
}
4444+
else if (STRCMP(hi->hi_key, "term_cols") == 0)
4445+
{
4446+
if (!(supported2 & JO2_TERM_COLS))
4447+
break;
4448+
opt->jo_set |= JO2_TERM_COLS;
4449+
opt->jo_term_cols = get_tv_number(item);
4450+
}
4451+
else if (STRCMP(hi->hi_key, "vertical") == 0)
4452+
{
4453+
if (!(supported2 & JO2_VERTICAL))
4454+
break;
4455+
opt->jo_set |= JO2_VERTICAL;
4456+
opt->jo_vertical = get_tv_number(item);
4457+
}
44374458
#endif
44384459
else if (STRCMP(hi->hi_key, "env") == 0)
44394460
{
4440-
if (!(supported & JO2_ENV))
4461+
if (!(supported2 & JO2_ENV))
44414462
break;
44424463
opt->jo_set |= JO2_ENV;
44434464
opt->jo_env = item->vval.v_dict;
44444465
++item->vval.v_dict->dv_refcount;
44454466
}
44464467
else if (STRCMP(hi->hi_key, "cwd") == 0)
44474468
{
4448-
if (!(supported & JO2_CWD))
4469+
if (!(supported2 & JO2_CWD))
44494470
break;
44504471
opt->jo_cwd = get_tv_string_buf_chk(item, opt->jo_cwd_buf);
44514472
if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd))
@@ -4956,7 +4977,7 @@ job_start(typval_T *argvars, jobopt_T *opt_arg)
49564977
opt.jo_mode = MODE_NL;
49574978
if (get_job_options(&argvars[1], &opt,
49584979
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT
4959-
+ JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE) == FAIL)
4980+
+ JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE, 0) == FAIL)
49604981
goto theend;
49614982
}
49624983

src/evalfunc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
20212021
return;
20222022
clear_job_options(&opt);
20232023
if (get_job_options(&argvars[1], &opt,
2024-
JO_CB_ALL + JO_TIMEOUT_ALL + JO_MODE_ALL) == OK)
2024+
JO_CB_ALL + JO_TIMEOUT_ALL + JO_MODE_ALL, 0) == OK)
20252025
channel_set_options(channel, &opt);
20262026
free_job_options(&opt);
20272027
}
@@ -2045,7 +2045,7 @@ f_ch_status(typval_T *argvars, typval_T *rettv)
20452045
if (argvars[1].v_type != VAR_UNKNOWN)
20462046
{
20472047
clear_job_options(&opt);
2048-
if (get_job_options(&argvars[1], &opt, JO_PART) == OK
2048+
if (get_job_options(&argvars[1], &opt, JO_PART, 0) == OK
20492049
&& (opt.jo_set & JO_PART))
20502050
part = opt.jo_part;
20512051
}
@@ -6783,7 +6783,7 @@ f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
67836783
if (job == NULL)
67846784
return;
67856785
clear_job_options(&opt);
6786-
if (get_job_options(&argvars[1], &opt, JO_STOPONEXIT + JO_EXIT_CB) == OK)
6786+
if (get_job_options(&argvars[1], &opt, JO_STOPONEXIT + JO_EXIT_CB, 0) == OK)
67876787
job_set_options(job, &opt);
67886788
free_job_options(&opt);
67896789
}

src/proto/channel.pro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ ch_mode_T channel_get_mode(channel_T *channel, ch_part_T part);
5151
int channel_get_timeout(channel_T *channel, ch_part_T part);
5252
void clear_job_options(jobopt_T *opt);
5353
void free_job_options(jobopt_T *opt);
54-
int get_job_options(typval_T *tv, jobopt_T *opt, int supported);
54+
int get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2);
5555
channel_T *get_channel_arg(typval_T *tv, int check_open, int reading, ch_part_T part);
56-
job_T *job_alloc(void);
57-
void job_cleanup(job_T *job);
5856
void job_free_all(void);
57+
void job_cleanup(job_T *job);
5958
int set_ref_in_job(int copyID);
6059
void job_unref(job_T *job);
6160
int free_unused_jobs_contents(int copyID, int mask);
6261
void free_unused_jobs(int copyID, int mask);
62+
job_T *job_alloc(void);
6363
void job_set_options(job_T *job, jobopt_T *opt);
6464
void job_stop_on_exit(void);
6565
int has_pending_job(void);

src/structs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,10 @@ struct channel_S {
16881688
#define JO2_TERM_FINISH 0x0008 /* "term_finish" */
16891689
#define JO2_ENV 0x0010 /* "env" */
16901690
#define JO2_CWD 0x0020 /* "cwd" */
1691-
#define JO2_ALL 0x003F
1691+
#define JO2_TERM_ROWS 0x0040 /* "term_rows" */
1692+
#define JO2_TERM_COLS 0x0080 /* "term_cols" */
1693+
#define JO2_VERTICAL 0x0100 /* "vertical" */
1694+
#define JO2_ALL 0x01FF
16921695

16931696
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
16941697
#define JO_CB_ALL \
@@ -1748,6 +1751,7 @@ typedef struct
17481751
/* when non-zero run the job in a terminal window of this size */
17491752
int jo_term_rows;
17501753
int jo_term_cols;
1754+
int jo_vertical;
17511755
char_u *jo_term_name;
17521756
int jo_term_finish;
17531757
#endif

src/terminal.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ setup_job_options(jobopt_T *opt, int rows, int cols)
237237
opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
238238
opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
239239
opt->jo_pty = TRUE;
240-
opt->jo_term_rows = rows;
241-
opt->jo_term_cols = cols;
240+
if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
241+
opt->jo_term_rows = rows;
242+
if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
243+
opt->jo_term_cols = cols;
242244
}
243245

244246
static void
@@ -2361,11 +2363,14 @@ f_term_start(typval_T *argvars, typval_T *rettv)
23612363
if (argvars[1].v_type != VAR_UNKNOWN
23622364
&& get_job_options(&argvars[1], &opt,
23632365
JO_TIMEOUT_ALL + JO_STOPONEXIT
2364-
+ JO_EXIT_CB + JO_CLOSE_CALLBACK
2365-
+ JO2_TERM_NAME + JO2_TERM_FINISH
2366-
+ JO2_CWD + JO2_ENV) == FAIL)
2366+
+ JO_EXIT_CB + JO_CLOSE_CALLBACK,
2367+
JO2_TERM_NAME + JO2_TERM_FINISH
2368+
+ JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL
2369+
+ JO2_CWD + JO2_ENV) == FAIL)
23672370
return;
23682371

2372+
if (opt.jo_vertical)
2373+
cmdmod.split = WSP_VERT;
23692374
term_start(cmd, &opt);
23702375

23712376
if (curbuf->b_term != NULL)

src/testdir/test_terminal.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,43 @@ func Test_terminal_size()
247247
bwipe!
248248
call assert_equal(5, size[0])
249249

250+
call term_start(cmd, {'term_rows': 6})
251+
let size = term_getsize('')
252+
bwipe!
253+
call assert_equal(6, size[0])
254+
250255
vsplit
251256
exe '5,33terminal ' . cmd
252257
let size = term_getsize('')
253258
bwipe!
254259
call assert_equal([5, 33], size)
255260

261+
call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
262+
let size = term_getsize('')
263+
bwipe!
264+
call assert_equal([6, 36], size)
265+
256266
exe 'vertical 20terminal ' . cmd
257267
let size = term_getsize('')
258268
bwipe!
259269
call assert_equal(20, size[1])
260270

271+
call term_start(cmd, {'vertical': 1, 'term_cols': 26})
272+
let size = term_getsize('')
273+
bwipe!
274+
call assert_equal(26, size[1])
275+
261276
split
262277
exe 'vertical 6,20terminal ' . cmd
263278
let size = term_getsize('')
264279
bwipe!
265280
call assert_equal([6, 20], size)
281+
282+
call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27})
283+
let size = term_getsize('')
284+
bwipe!
285+
call assert_equal([7, 27], size)
286+
266287
endfunc
267288

268289
func Test_finish_close()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
908,
772774
/**/
773775
907,
774776
/**/

0 commit comments

Comments
 (0)