Skip to content

Commit c2ce52c

Browse files
committed
patch 8.0.0832: terminal function arguments are not consistent
Problem: Terminal function arguments are not consistent. Solution: Use one-based instead of zero-based rows and cols. Use "." for the current row.
1 parent 12d853f commit c2ce52c

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

runtime/doc/eval.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 30
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Aug 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1815,7 +1815,7 @@ v:scrollstart String describing the script or function that caused the
18151815
hit-enter prompt.
18161816

18171817
*v:servername* *servername-variable*
1818-
v:servername The resulting registered |x11-clientserver| name if any.
1818+
v:servername The resulting registered |client-server-name| if any.
18191819
Read-only.
18201820

18211821

@@ -2372,12 +2372,12 @@ tempname() String name for a temporary file
23722372
term_getattr({attr}, {what} Number get the value of attribute {what}
23732373
term_getcursor({buf}) List get the cursor position of a terminal
23742374
term_getjob({buf}) Job get the job associated with a terminal
2375-
term_getline({buf}[, {row}]) String get a line of text from a terminal
2375+
term_getline({buf}, {row}) String get a line of text from a terminal
23762376
term_getsize({buf}) List get the size of a terminal
23772377
term_getstatus({buf}) String get the status of a terminal
23782378
term_gettitle({buf}) String get the title of a terminal
23792379
term_list() List get the list of terminal buffers
2380-
term_scrape({buf}[, {row}]) List get row of a terminal screen
2380+
term_scrape({buf}, {row}) List get row of a terminal screen
23812381
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
23822382
term_start({cmd}, {options}) Job open a terminal window and run a job
23832383
term_wait({buf}) Number wait for screen to be updated
@@ -7916,8 +7916,9 @@ term_getattr({attr}, {what}) *term_getattr()*
79167916
term_getcursor({buf}) *term_getcursor()*
79177917
Get the cusor position of terminal {buf}. Returns a list with
79187918
three numbers: [rows, cols, visible]. "rows" and "cols" are
7919-
zero based. "visible" is one when the cursor is visible, zero
7920-
when it is hidden.
7919+
one based, the first sceen cell is row 1, column 1.
7920+
"visible" is one when the cursor is visible, zero when it is
7921+
hidden.
79217922

79227923
This is the cursor position of the terminal itself, not of the
79237924
Vim window.
@@ -7930,13 +7931,12 @@ term_getjob({buf}) *term_getjob()*
79307931
Get the Job associated with terminal window {buf}.
79317932
{buf} is used as with |term_getsize()|.
79327933

7933-
term_getline({buf} [, {row}]) *term_getline()*
7934+
term_getline({buf}, {row}) *term_getline()*
79347935
Get a line of text from the terminal window of {buf}.
79357936
{buf} is used as with |term_getsize()|.
79367937

7937-
The first line has {row} zero. When {row} is invalid an empty
7938-
string is returned. When {row} is omitted, the cursor line is
7939-
used.
7938+
The first line has {row} one. When {row} "." the cursor line
7939+
is used. When {row} is invalid an empty string is returned.
79407940

79417941
term_getsize({buf}) *term_getsize()*
79427942
Get the size of terminal {buf}. Returns a list with two
@@ -7971,12 +7971,12 @@ term_list() *term_list()*
79717971
Return a list with the buffer numbers of all buffers for
79727972
terminal windows.
79737973

7974-
term_scrape({buf} [, {row}]) *term_scrape()*
7974+
term_scrape({buf}, {row}) *term_scrape()*
79757975
Get the contents of {row} of terminal screen of {buf}.
79767976
For {buf} see |term_getsize()|.
79777977

7978-
The first {row} is zero. When {row} is invalid an empty list
7979-
is returned. When {row} is omitted the cursor line is used.
7978+
The first line has {row} one. When {row} "." the cursor line
7979+
is used. When {row} is invalid an empty string is returned.
79807980

79817981
Return a List containing a Dict for each screen cell:
79827982
"chars" character(s) at the cell
@@ -8728,6 +8728,7 @@ tag_any_white Compiled with support for any white characters in tags
87288728
files |tag-any-white|.
87298729
tcl Compiled with Tcl interface.
87308730
termguicolors Compiled with true color in terminal support.
8731+
terminal Compiled with |terminal| support.
87318732
terminfo Compiled with terminfo instead of termcap.
87328733
termresponse Compiled with support for |t_RV| and |v:termresponse|.
87338734
textobjects Compiled with support for |text-objects|.

src/terminal.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
* that buffer, attributes come from the scrollback buffer tl_scrollback.
3737
*
3838
* TODO:
39-
* - Use "." for current line instead of optional argument.
40-
* - make row and cols one-based instead of zero-based in term_ functions.
4139
* - Add StatusLineTerm highlighting
4240
* - in bash mouse clicks are inserting characters.
4341
* - mouse scroll: when over other window, scroll that window.
@@ -1773,8 +1771,8 @@ f_term_getcursor(typval_T *argvars, typval_T *rettv)
17731771
return;
17741772

17751773
l = rettv->vval.v_list;
1776-
list_append_number(l, buf->b_term->tl_cursor_pos.row);
1777-
list_append_number(l, buf->b_term->tl_cursor_pos.col);
1774+
list_append_number(l, buf->b_term->tl_cursor_pos.row + 1);
1775+
list_append_number(l, buf->b_term->tl_cursor_pos.col + 1);
17781776
list_append_number(l, buf->b_term->tl_cursor_visible);
17791777
}
17801778

@@ -1796,6 +1794,16 @@ f_term_getjob(typval_T *argvars, typval_T *rettv)
17961794
++rettv->vval.v_job->jv_refcount;
17971795
}
17981796

1797+
static int
1798+
get_row_number(typval_T *tv, term_T *term)
1799+
{
1800+
if (tv->v_type == VAR_STRING
1801+
&& tv->vval.v_string != NULL
1802+
&& STRCMP(tv->vval.v_string, ".") == 0)
1803+
return term->tl_cursor_pos.row;
1804+
return (int)get_tv_number(tv) - 1;
1805+
}
1806+
17991807
/*
18001808
* "term_getline(buf, row)" function
18011809
*/
@@ -1810,10 +1818,7 @@ f_term_getline(typval_T *argvars, typval_T *rettv)
18101818
if (buf == NULL)
18111819
return;
18121820
term = buf->b_term;
1813-
if (argvars[1].v_type == VAR_UNKNOWN)
1814-
row = term->tl_cursor_pos.row;
1815-
else
1816-
row = (int)get_tv_number(&argvars[1]);
1821+
row = get_row_number(&argvars[1], term);
18171822

18181823
if (term->tl_vterm == NULL)
18191824
{
@@ -1944,10 +1949,7 @@ f_term_scrape(typval_T *argvars, typval_T *rettv)
19441949
screen = vterm_obtain_screen(term->tl_vterm);
19451950

19461951
l = rettv->vval.v_list;
1947-
if (argvars[1].v_type == VAR_UNKNOWN)
1948-
pos.row = term->tl_cursor_pos.row;
1949-
else
1950-
pos.row = (int)get_tv_number(&argvars[1]);
1952+
pos.row = get_row_number(&argvars[1], term);
19511953
for (pos.col = 0; pos.col < term->tl_cols; )
19521954
{
19531955
dict_T *dcell;

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+
832,
772774
/**/
773775
831,
774776
/**/

0 commit comments

Comments
 (0)