Skip to content

Commit a42d363

Browse files
committed
patch 8.0.1711: term_setsize() is not implemented yet
Problem: Term_setsize() is not implemented yet. Solution: Implement it.
1 parent 2a43230 commit a42d363

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

runtime/doc/eval.txt

+27-2
Original file line numberDiff line numberDiff line change
@@ -8402,6 +8402,24 @@ term_setansicolors({buf}, {colors}) *term_setansicolors()*
84028402
color codes, like those accepted by |highlight-guifg|.
84038403
Also see |term_getansicolors()| and |g:terminal_ansi_colors|.
84048404

8405+
The colors normally are:
8406+
0 black
8407+
1 dark red
8408+
2 dark green
8409+
3 brown
8410+
4 dark blue
8411+
5 dark magenta
8412+
6 dark cyan
8413+
7 light grey
8414+
8 dark grey
8415+
9 red
8416+
10 green
8417+
11 yellow
8418+
12 blue
8419+
13 magenta
8420+
14 cyan
8421+
15 white
8422+
84058423
These colors are used in the GUI and in the terminal when
84068424
'termguicolors' is set. When not using GUI colors (GUI mode
84078425
or |termguicolors|), the terminal window always uses the 16
@@ -8431,8 +8449,15 @@ term_setrestore({buf}, {command}) *term_setrestore()*
84318449
Use "NONE" to not restore this window.
84328450
{only available when compiled with the |+terminal| feature}
84338451

8434-
term_setsize({buf}, {expr}) *term_setsize()*
8435-
Not implemented yet.
8452+
term_setsize({buf}, {rows}, {cols}) *term_setsize()*
8453+
Set the size of terminal {buf}. The size of the window
8454+
containing the terminal will also be adjusted, if possible.
8455+
If {rows} or {cols} is zero or negative, that dimension is not
8456+
changed.
8457+
8458+
{buf} must be the buffer number of a terminal window. Use an
8459+
empty string for the current buffer. If the buffer does not
8460+
exist or is not a terminal window, an error is given.
84368461
{only available when compiled with the |+terminal| feature}
84378462

84388463
term_start({cmd}, {options}) *term_start()*

src/evalfunc.c

+1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ static struct fst
876876
# endif
877877
{"term_setkill", 2, 2, f_term_setkill},
878878
{"term_setrestore", 2, 2, f_term_setrestore},
879+
{"term_setsize", 3, 3, f_term_setsize},
879880
{"term_start", 1, 2, f_term_start},
880881
{"term_wait", 1, 2, f_term_wait},
881882
#endif

src/proto/terminal.pro

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ int term_swap_diff(void);
3232
void f_term_dumpdiff(typval_T *argvars, typval_T *rettv);
3333
void f_term_dumpload(typval_T *argvars, typval_T *rettv);
3434
void f_term_getaltscreen(typval_T *argvars, typval_T *rettv);
35-
void f_term_getansicolors(typval_T *argvars, typval_T *rettv);
3635
void f_term_getattr(typval_T *argvars, typval_T *rettv);
3736
void f_term_getcursor(typval_T *argvars, typval_T *rettv);
3837
void f_term_getjob(typval_T *argvars, typval_T *rettv);
3938
void f_term_getline(typval_T *argvars, typval_T *rettv);
4039
void f_term_getscrolled(typval_T *argvars, typval_T *rettv);
4140
void f_term_getsize(typval_T *argvars, typval_T *rettv);
41+
void f_term_setsize(typval_T *argvars, typval_T *rettv);
4242
void f_term_getstatus(typval_T *argvars, typval_T *rettv);
4343
void f_term_gettitle(typval_T *argvars, typval_T *rettv);
4444
void f_term_gettty(typval_T *argvars, typval_T *rettv);
4545
void f_term_list(typval_T *argvars, typval_T *rettv);
4646
void f_term_scrape(typval_T *argvars, typval_T *rettv);
4747
void f_term_sendkeys(typval_T *argvars, typval_T *rettv);
48+
void f_term_getansicolors(typval_T *argvars, typval_T *rettv);
4849
void f_term_setansicolors(typval_T *argvars, typval_T *rettv);
4950
void f_term_setrestore(typval_T *argvars, typval_T *rettv);
5051
void f_term_setkill(typval_T *argvars, typval_T *rettv);

src/terminal.c

+27-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
* TODO:
4141
* - Win32: Make terminal used for :!cmd in the GUI work better. Allow for
4242
* redirection. Probably in call to channel_set_pipes().
43-
* - implement term_setsize()
4443
* - add an optional limit for the scrollback size. When reaching it remove
4544
* 10% at the start.
4645
* - 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)
46024601
list_append_number(l, buf->b_term->tl_cols);
46034602
}
46044603

4604+
/*
4605+
* "term_setsize(buf, rows, cols)" function
4606+
*/
4607+
void
4608+
f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
4609+
{
4610+
buf_T *buf = term_get_buf(argvars, "term_setsize()");
4611+
term_T *term;
4612+
varnumber_T rows, cols;
4613+
4614+
if (buf == NULL || buf->b_term->tl_vterm == NULL)
4615+
return;
4616+
term = buf->b_term;
4617+
rows = get_tv_number(&argvars[1]);
4618+
rows = rows <= 0 ? term->tl_rows : rows;
4619+
cols = get_tv_number(&argvars[2]);
4620+
cols = cols <= 0 ? term->tl_cols : cols;
4621+
vterm_set_size(term->tl_vterm, rows, cols);
4622+
/* handle_resize() will resize the windows */
4623+
4624+
/* Get and remember the size we ended up with. Update the pty. */
4625+
vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
4626+
term_report_winsize(term, term->tl_rows, term->tl_cols);
4627+
}
4628+
46054629
/*
46064630
* "term_getstatus(buf)" function
46074631
*/
@@ -5432,7 +5456,7 @@ term_free_vterm(term_T *term)
54325456
}
54335457

54345458
/*
5435-
* Request size to terminal.
5459+
* Report the size to the terminal.
54365460
*/
54375461
static void
54385462
term_report_winsize(term_T *term, int rows, int cols)
@@ -5514,7 +5538,7 @@ term_free_vterm(term_T *term)
55145538
}
55155539

55165540
/*
5517-
* Request size to terminal.
5541+
* Report the size to the terminal.
55185542
*/
55195543
static void
55205544
term_report_winsize(term_T *term, int rows, int cols)

src/testdir/test_terminal.vim

+11-2
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,18 @@ func Test_terminal_size()
286286

287287
vsplit
288288
exe 'terminal ++rows=5 ++cols=33 ' . cmd
289-
let size = term_getsize('')
289+
call assert_equal([5, 33], term_getsize(''))
290+
291+
call term_setsize('', 6, 0)
292+
call assert_equal([6, 33], term_getsize(''))
293+
294+
call term_setsize('', 0, 35)
295+
call assert_equal([6, 35], term_getsize(''))
296+
297+
call term_setsize('', 7, 30)
298+
call assert_equal([7, 30], term_getsize(''))
299+
290300
bwipe!
291-
call assert_equal([5, 33], size)
292301

293302
call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
294303
let size = term_getsize('')

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static char *(features[]) =
762762

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1711,
765767
/**/
766768
1710,
767769
/**/

0 commit comments

Comments
 (0)