]> granicus.if.org Git - vim/commitdiff
patch 8.0.0908: cannot set terminal size with options v8.0.0908
authorBram Moolenaar <Bram@vim.org>
Fri, 11 Aug 2017 19:51:23 +0000 (21:51 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 11 Aug 2017 19:51:23 +0000 (21:51 +0200)
Problem:    Cannot set terminal size with options.
Solution:   Add "term_rows", "term_cols" and "vertical".

runtime/doc/eval.txt
src/channel.c
src/evalfunc.c
src/proto/channel.pro
src/structs.h
src/terminal.c
src/testdir/test_terminal.vim
src/version.c

index 2705f2a5b8b5537eac03dadd52892430b986eaf9..b5bc10028304ea078d5fe00ffc507d4ccd345a25 100644 (file)
@@ -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.
index 3126cbd78f9a472310d6e7f9203d856fcbb57686..b220f7166b71be4dd273ca4fb8e6c598b2a25588 100644 (file)
@@ -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,10 +4434,31 @@ 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;
@@ -4445,7 +4466,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
            }
            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;
     }
 
index 6cb0ed7d722251df50e37879f34ed84193c60d1d..1721e039c54aba062188ae8f0c88406e98a224ca 100644 (file)
@@ -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);
 }
index 6cd099ef45622448739f73e9fa7b2af4017c0ba5..3bbbf2866172110f8853c2d31f54cab06ef497cc 100644 (file)
@@ -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);
index 16f2cc1d0731ba356993ec2a4c8ebd04ce204055..67b4a9b203c9c15f25f8909d4db6fea507715d72 100644 (file)
@@ -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
index c215b3fa8ca2c59d6d525ed01c6e9f304d05249c..bab2a5ba47cc68fdac51588a77597ebcdcdb5986 100644 (file)
@@ -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)
index afa6b67da18a136919ffc7d085b63a27da9af868..d585751499e601cc2e7b6605b3277a984cea2153 100644 (file)
@@ -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()
index 40515883cef6e48fbc8407791013be3c24966136..acc855c874995ec344b1cc2b5cea5bf4e2715f75 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    908,
 /**/
     907,
 /**/