]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.1711: term_setsize() is not implemented yet v8.0.1711
authorBram Moolenaar <Bram@vim.org>
Sat, 14 Apr 2018 15:05:38 +0000 (17:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 14 Apr 2018 15:05:38 +0000 (17:05 +0200)
Problem:    Term_setsize() is not implemented yet.
Solution:   Implement it.

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

index 1868f4ee73e95614fc5d1d721bafe692f6686e1f..35e7063680eaaac7ab9d13f7bcb8f940e067009f 100644 (file)
@@ -8402,6 +8402,24 @@ term_setansicolors({buf}, {colors})                      *term_setansicolors()*
                color codes, like those accepted by |highlight-guifg|.
                Also see |term_getansicolors()| and |g:terminal_ansi_colors|.
 
+               The colors normally are:
+                       0    black
+                       1    dark red
+                       2    dark green
+                       3    brown
+                       4    dark blue
+                       5    dark magenta
+                       6    dark cyan
+                       7    light grey
+                       8    dark grey
+                       9    red
+                       10   green
+                       11   yellow
+                       12   blue
+                       13   magenta
+                       14   cyan
+                       15   white
+
                These colors are used in the GUI and in the terminal when
                'termguicolors' is set.  When not using GUI colors (GUI mode
                or |termguicolors|), the terminal window always uses the 16
@@ -8431,8 +8449,15 @@ term_setrestore({buf}, {command})                        *term_setrestore()*
                Use "NONE" to not restore this window.
                {only available when compiled with the |+terminal| feature}
 
-term_setsize({buf}, {expr})                            *term_setsize()*
-               Not implemented yet.
+term_setsize({buf}, {rows}, {cols})                    *term_setsize()*
+               Set the size of terminal {buf}. The size of the window
+               containing the terminal will also be adjusted, if possible.
+               If {rows} or {cols} is zero or negative, that dimension is not
+               changed.
+
+               {buf} must be the buffer number of a terminal window.  Use an
+               empty string for the current buffer.  If the buffer does not
+               exist or is not a terminal window, an error is given.
                {only available when compiled with the |+terminal| feature}
 
 term_start({cmd}, {options})                           *term_start()*
index 4b09951852b0aa740f979d23d754379ccdbc5b82..599d61ab81244251bb372f99bc5d6246a4e3ca4f 100644 (file)
@@ -876,6 +876,7 @@ static struct fst
 # endif
     {"term_setkill",   2, 2, f_term_setkill},
     {"term_setrestore",        2, 2, f_term_setrestore},
+    {"term_setsize",   3, 3, f_term_setsize},
     {"term_start",     1, 2, f_term_start},
     {"term_wait",      1, 2, f_term_wait},
 #endif
index f7cea5a1615e82b12be9ce7c5296c0661fe9b30a..78b640f7a59820bda650ceff31c4f5e3d3951217 100644 (file)
@@ -32,19 +32,20 @@ int term_swap_diff(void);
 void f_term_dumpdiff(typval_T *argvars, typval_T *rettv);
 void f_term_dumpload(typval_T *argvars, typval_T *rettv);
 void f_term_getaltscreen(typval_T *argvars, typval_T *rettv);
-void f_term_getansicolors(typval_T *argvars, typval_T *rettv);
 void f_term_getattr(typval_T *argvars, typval_T *rettv);
 void f_term_getcursor(typval_T *argvars, typval_T *rettv);
 void f_term_getjob(typval_T *argvars, typval_T *rettv);
 void f_term_getline(typval_T *argvars, typval_T *rettv);
 void f_term_getscrolled(typval_T *argvars, typval_T *rettv);
 void f_term_getsize(typval_T *argvars, typval_T *rettv);
+void f_term_setsize(typval_T *argvars, typval_T *rettv);
 void f_term_getstatus(typval_T *argvars, typval_T *rettv);
 void f_term_gettitle(typval_T *argvars, typval_T *rettv);
 void f_term_gettty(typval_T *argvars, typval_T *rettv);
 void f_term_list(typval_T *argvars, typval_T *rettv);
 void f_term_scrape(typval_T *argvars, typval_T *rettv);
 void f_term_sendkeys(typval_T *argvars, typval_T *rettv);
+void f_term_getansicolors(typval_T *argvars, typval_T *rettv);
 void f_term_setansicolors(typval_T *argvars, typval_T *rettv);
 void f_term_setrestore(typval_T *argvars, typval_T *rettv);
 void f_term_setkill(typval_T *argvars, typval_T *rettv);
index f980a099293c06ade3e3629ca8438c21d0c141f4..09d48872da83aa68a6dee4354962e4ebea0948fe 100644 (file)
@@ -40,7 +40,6 @@
  * TODO:
  * - Win32: Make terminal used for :!cmd in the GUI work better.  Allow for
  *   redirection.  Probably in call to channel_set_pipes().
- * - implement term_setsize()
  * - add an optional limit for the scrollback size.  When reaching it remove
  *   10% at the start.
  * - Copy text in the vterm to the Vim buffer once in a while, so that
@@ -4602,6 +4601,31 @@ f_term_getsize(typval_T *argvars, typval_T *rettv)
     list_append_number(l, buf->b_term->tl_cols);
 }
 
+/*
+ * "term_setsize(buf, rows, cols)" function
+ */
+    void
+f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+    buf_T      *buf = term_get_buf(argvars, "term_setsize()");
+    term_T     *term;
+    varnumber_T rows, cols;
+
+    if (buf == NULL || buf->b_term->tl_vterm == NULL)
+       return;
+    term = buf->b_term;
+    rows = get_tv_number(&argvars[1]);
+    rows = rows <= 0 ? term->tl_rows : rows;
+    cols = get_tv_number(&argvars[2]);
+    cols = cols <= 0 ? term->tl_cols : cols;
+    vterm_set_size(term->tl_vterm, rows, cols);
+    /* handle_resize() will resize the windows */
+
+    /* Get and remember the size we ended up with.  Update the pty. */
+    vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
+    term_report_winsize(term, term->tl_rows, term->tl_cols);
+}
+
 /*
  * "term_getstatus(buf)" function
  */
@@ -5432,7 +5456,7 @@ term_free_vterm(term_T *term)
 }
 
 /*
- * Request size to terminal.
+ * Report the size to the terminal.
  */
     static void
 term_report_winsize(term_T *term, int rows, int cols)
@@ -5514,7 +5538,7 @@ term_free_vterm(term_T *term)
 }
 
 /*
- * Request size to terminal.
+ * Report the size to the terminal.
  */
     static void
 term_report_winsize(term_T *term, int rows, int cols)
index e97ee069104ebff6bf0172521c46bce3b2d61a70..137de7ddd60b4e9bced213ea2e2def6ed51a05d2 100644 (file)
@@ -286,9 +286,18 @@ func Test_terminal_size()
 
   vsplit
   exe 'terminal ++rows=5 ++cols=33 ' . cmd
-  let size = term_getsize('')
+  call assert_equal([5, 33], term_getsize(''))
+
+  call term_setsize('', 6, 0)
+  call assert_equal([6, 33], term_getsize(''))
+
+  call term_setsize('', 0, 35)
+  call assert_equal([6, 35], term_getsize(''))
+
+  call term_setsize('', 7, 30)
+  call assert_equal([7, 30], term_getsize(''))
+
   bwipe!
-  call assert_equal([5, 33], size)
 
   call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
   let size = term_getsize('')
index b340f11701fe3c4336ff9e136bf4e8464a94c181..255e24bd989962660833988c47a00029f0346fcf 100644 (file)
@@ -762,6 +762,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1711,
 /**/
     1710,
 /**/