Permalink
Browse files

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".
  • Loading branch information...
brammool committed Aug 11, 2017
1 parent 89e06c8 commit 08d384ff3aa0366c18fb87ed215b1b4bdf9b1745
Showing with 86 additions and 26 deletions.
  1. +11 −4 runtime/doc/eval.txt
  2. +31 −10 src/channel.c
  3. +3 −3 src/evalfunc.c
  4. +3 −3 src/proto/channel.pro
  5. +5 −1 src/structs.h
  6. +10 −5 src/terminal.c
  7. +21 −0 src/testdir/test_terminal.vim
  8. +2 −0 src/version.c
View
@@ -8050,8 +8050,10 @@ term_sendkeys({buf}, {keys}) *term_sendkeys()*
term_start({cmd}, {options}) *term_start()*
Open a terminal window and run {cmd} in it.
Returns the buffer number of the terminal window.
When opening the window fails zero is returned.
Returns the buffer number of the terminal window. If {cmd}
cannot be executed the window does open and shows an error
message.
If opening the window fails zero is returned.
{options} are similar to what is used for |job_start()|, see
|job-options|. However, not all options can be used. These
@@ -8067,10 +8069,15 @@ term_start({cmd}, {options}) *term_start()*
connected to the terminal. When I/O is connected to the
terminal then the callback function for that part is not used.
There are two extra options:
There are extra options:
"term_name" name to use for the buffer name, instead
of the command name.
"term_finish" What todo when the job is finished:
"term_rows" vertical size to use for the terminal,
instead of using 'termsize'
"term_cols" horizontal size to use for the terminal,
instead of using 'termsize'
"vertical" split the window vertically
"term_finish" What to do when the job is finished:
"close": close any windows
"open": open window if needed
Note that "open" can be interruptive.
View
@@ -927,7 +927,7 @@ channel_open_func(typval_T *argvars)
opt.jo_mode = MODE_JSON;
opt.jo_timeout = 2000;
if (get_job_options(&argvars[1], &opt,
JO_MODE_ALL + JO_CB_ALL + JO_WAITTIME + JO_TIMEOUT_ALL) == FAIL)
JO_MODE_ALL + JO_CB_ALL + JO_WAITTIME + JO_TIMEOUT_ALL, 0) == FAIL)
goto theend;
if (opt.jo_timeout < 0)
{
@@ -3429,7 +3429,7 @@ common_channel_read(typval_T *argvars, typval_T *rettv, int raw)
rettv->vval.v_string = NULL;
clear_job_options(&opt);
if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID)
if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID, 0)
== FAIL)
goto theend;
@@ -3612,7 +3612,7 @@ send_common(
part_send = channel_part_send(channel);
*part_read = channel_part_read(channel);
if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT) == FAIL)
if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT, 0) == FAIL)
return NULL;
/* Set the callback. An empty callback means no callback and not reading
@@ -4169,11 +4169,11 @@ part_from_char(int c)
/*
* Get the option entries from the dict in "tv", parse them and put the result
* in "opt".
* Only accept options in "supported".
* Only accept JO_ options in "supported" and JO2_ options in "supported2".
* If an option value is invalid return FAIL.
*/
int
get_job_options(typval_T *tv, jobopt_T *opt, int supported)
get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
{
typval_T *item;
char_u *val;
@@ -4411,7 +4411,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
#ifdef FEAT_TERMINAL
else if (STRCMP(hi->hi_key, "term_name") == 0)
{
if (!(supported & JO2_TERM_NAME))
if (!(supported2 & JO2_TERM_NAME))
break;
opt->jo_set2 |= JO2_TERM_NAME;
opt->jo_term_name = get_tv_string_chk(item);
@@ -4423,7 +4423,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
}
else if (STRCMP(hi->hi_key, "term_finish") == 0)
{
if (!(supported & JO2_TERM_FINISH))
if (!(supported2 & JO2_TERM_FINISH))
break;
val = get_tv_string(item);
if (STRCMP(val, "open") != 0 && STRCMP(val, "close") != 0)
@@ -4434,18 +4434,39 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
opt->jo_set2 |= JO2_TERM_FINISH;
opt->jo_term_finish = *val;
}
else if (STRCMP(hi->hi_key, "term_rows") == 0)
{
if (!(supported2 & JO2_TERM_ROWS))
break;
opt->jo_set |= JO2_TERM_ROWS;
opt->jo_term_rows = get_tv_number(item);
}
else if (STRCMP(hi->hi_key, "term_cols") == 0)
{
if (!(supported2 & JO2_TERM_COLS))
break;
opt->jo_set |= JO2_TERM_COLS;
opt->jo_term_cols = get_tv_number(item);
}
else if (STRCMP(hi->hi_key, "vertical") == 0)
{
if (!(supported2 & JO2_VERTICAL))
break;
opt->jo_set |= JO2_VERTICAL;
opt->jo_vertical = get_tv_number(item);
}
#endif
else if (STRCMP(hi->hi_key, "env") == 0)
{
if (!(supported & JO2_ENV))
if (!(supported2 & JO2_ENV))
break;
opt->jo_set |= JO2_ENV;
opt->jo_env = item->vval.v_dict;
++item->vval.v_dict->dv_refcount;
}
else if (STRCMP(hi->hi_key, "cwd") == 0)
{
if (!(supported & JO2_CWD))
if (!(supported2 & JO2_CWD))
break;
opt->jo_cwd = get_tv_string_buf_chk(item, opt->jo_cwd_buf);
if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd))
@@ -4956,7 +4977,7 @@ job_start(typval_T *argvars, jobopt_T *opt_arg)
opt.jo_mode = MODE_NL;
if (get_job_options(&argvars[1], &opt,
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT
+ JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE) == FAIL)
+ JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE, 0) == FAIL)
goto theend;
}
View
@@ -2021,7 +2021,7 @@ f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
return;
clear_job_options(&opt);
if (get_job_options(&argvars[1], &opt,
JO_CB_ALL + JO_TIMEOUT_ALL + JO_MODE_ALL) == OK)
JO_CB_ALL + JO_TIMEOUT_ALL + JO_MODE_ALL, 0) == OK)
channel_set_options(channel, &opt);
free_job_options(&opt);
}
@@ -2045,7 +2045,7 @@ f_ch_status(typval_T *argvars, typval_T *rettv)
if (argvars[1].v_type != VAR_UNKNOWN)
{
clear_job_options(&opt);
if (get_job_options(&argvars[1], &opt, JO_PART) == OK
if (get_job_options(&argvars[1], &opt, JO_PART, 0) == OK
&& (opt.jo_set & JO_PART))
part = opt.jo_part;
}
@@ -6783,7 +6783,7 @@ f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
if (job == NULL)
return;
clear_job_options(&opt);
if (get_job_options(&argvars[1], &opt, JO_STOPONEXIT + JO_EXIT_CB) == OK)
if (get_job_options(&argvars[1], &opt, JO_STOPONEXIT + JO_EXIT_CB, 0) == OK)
job_set_options(job, &opt);
free_job_options(&opt);
}
View
@@ -51,15 +51,15 @@ ch_mode_T channel_get_mode(channel_T *channel, ch_part_T part);
int channel_get_timeout(channel_T *channel, ch_part_T part);
void clear_job_options(jobopt_T *opt);
void free_job_options(jobopt_T *opt);
int get_job_options(typval_T *tv, jobopt_T *opt, int supported);
int get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2);
channel_T *get_channel_arg(typval_T *tv, int check_open, int reading, ch_part_T part);
job_T *job_alloc(void);
void job_cleanup(job_T *job);
void job_free_all(void);
void job_cleanup(job_T *job);
int set_ref_in_job(int copyID);
void job_unref(job_T *job);
int free_unused_jobs_contents(int copyID, int mask);
void free_unused_jobs(int copyID, int mask);
job_T *job_alloc(void);
void job_set_options(job_T *job, jobopt_T *opt);
void job_stop_on_exit(void);
int has_pending_job(void);
View
@@ -1688,7 +1688,10 @@ struct channel_S {
#define JO2_TERM_FINISH 0x0008 /* "term_finish" */
#define JO2_ENV 0x0010 /* "env" */
#define JO2_CWD 0x0020 /* "cwd" */
#define JO2_ALL 0x003F
#define JO2_TERM_ROWS 0x0040 /* "term_rows" */
#define JO2_TERM_COLS 0x0080 /* "term_cols" */
#define JO2_VERTICAL 0x0100 /* "vertical" */
#define JO2_ALL 0x01FF
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
#define JO_CB_ALL \
@@ -1748,6 +1751,7 @@ typedef struct
/* when non-zero run the job in a terminal window of this size */
int jo_term_rows;
int jo_term_cols;
int jo_vertical;
char_u *jo_term_name;
int jo_term_finish;
#endif
View
@@ -237,8 +237,10 @@ setup_job_options(jobopt_T *opt, int rows, int cols)
opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
opt->jo_pty = TRUE;
opt->jo_term_rows = rows;
opt->jo_term_cols = cols;
if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
opt->jo_term_rows = rows;
if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
opt->jo_term_cols = cols;
}
static void
@@ -2361,11 +2363,14 @@ f_term_start(typval_T *argvars, typval_T *rettv)
if (argvars[1].v_type != VAR_UNKNOWN
&& get_job_options(&argvars[1], &opt,
JO_TIMEOUT_ALL + JO_STOPONEXIT
+ JO_EXIT_CB + JO_CLOSE_CALLBACK
+ JO2_TERM_NAME + JO2_TERM_FINISH
+ JO2_CWD + JO2_ENV) == FAIL)
+ JO_EXIT_CB + JO_CLOSE_CALLBACK,
JO2_TERM_NAME + JO2_TERM_FINISH
+ JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL
+ JO2_CWD + JO2_ENV) == FAIL)
return;
if (opt.jo_vertical)
cmdmod.split = WSP_VERT;
term_start(cmd, &opt);
if (curbuf->b_term != NULL)
@@ -247,22 +247,43 @@ func Test_terminal_size()
bwipe!
call assert_equal(5, size[0])
call term_start(cmd, {'term_rows': 6})
let size = term_getsize('')
bwipe!
call assert_equal(6, size[0])
vsplit
exe '5,33terminal ' . cmd
let size = term_getsize('')
bwipe!
call assert_equal([5, 33], size)
call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
let size = term_getsize('')
bwipe!
call assert_equal([6, 36], size)
exe 'vertical 20terminal ' . cmd
let size = term_getsize('')
bwipe!
call assert_equal(20, size[1])
call term_start(cmd, {'vertical': 1, 'term_cols': 26})
let size = term_getsize('')
bwipe!
call assert_equal(26, size[1])
split
exe 'vertical 6,20terminal ' . cmd
let size = term_getsize('')
bwipe!
call assert_equal([6, 20], size)
call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27})
let size = term_getsize('')
bwipe!
call assert_equal([7, 27], size)
endfunc
func Test_finish_close()
View
@@ -769,6 +769,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
908,
/**/
907,
/**/

0 comments on commit 08d384f

Please sign in to comment.