# HG changeset patch # User Christian Brabandt # Date 1501432204 -7200 # Node ID d444e087b8fd409f9a7bd59a3ab23a3371b30b88 # Parent 8a2769a22c17d5ced7f42d54b9ce964c068e8c89 patch 8.0.0817: cannot get the terminal line at the cursor commit https://github.com/vim/vim/commit/22aad2f8806acf390568b8e524e53260a322aaa5 Author: Bram Moolenaar Date: Sun Jul 30 18:19:46 2017 +0200 patch 8.0.0817: cannot get the terminal line at the cursor Problem: Cannot get the line of a terminal window at the cursor. Solution: Make the row argunt optionsl. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/1898) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 8.0. Last change: 2017 Jul 29 +*eval.txt* For Vim version 8.0. Last change: 2017 Jul 30 VIM REFERENCE MANUAL by Bram Moolenaar @@ -2371,10 +2371,10 @@ tanh({expr}) Float hyperbolic tangent tempname() String name for a temporary file term_getattr({attr}, {what} Number get the value of attribute {what} term_getjob({buf}) Job get the job associated with a terminal -term_getline({buf}, {row}) String get a line of text from a terminal +term_getline({buf}[, {row}]) String get a line of text from a terminal term_getsize({buf}) List get the size of a terminal term_list() List get the list of terminal buffers -term_scrape({buf}, {row}) List get row of a terminal screen +term_scrape({buf}[, {row}]) List get row of a terminal screen term_sendkeys({buf}, {keys}) none send keystrokes to a terminal term_start({cmd}, {options}) Job open a terminal window and run a job term_wait({buf}) Number wait for screen to be updated @@ -7914,12 +7914,13 @@ term_getjob({buf}) *term_getjob()* Get the Job associated with terminal window {buf}. {buf} is used as with |term_getsize()|. -term_getline({buf}, {row}) *term_getline()* +term_getline({buf} [, {row}]) *term_getline()* Get a line of text from the terminal window of {buf}. {buf} is used as with |term_getsize()|. The first line has {row} zero. When {row} is invalid an empty - string is returned. + string is returned. When {row} is omitted, the cursor line is + used. term_getsize({buf}) *term_getsize()* Get the size of terminal {buf}. Returns a list with two @@ -7930,17 +7931,17 @@ term_getsize({buf}) *term_getsize()* buffer does not exist or is not a terminal window, an empty list is returned. -term_list(}) *term_list()* +term_list() *term_list()* Return a list with the buffer numbers of all buffers for terminal windows. -term_scrape({buf}, {row}) *term_scrape()* +term_scrape({buf} [, {row}]) *term_scrape()* Get the contents of {row} of terminal screen of {buf}. For {buf} see |term_getsize()|. The first {row} is zero. When {row} is invalid an empty list - is returned. - + is returned. When {row} is omitted the cursor line is used. + Return a List containing a Dict for each screen cell: "chars" character(s) at the cell "fg" foreground color as #rrggbb diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -833,10 +833,10 @@ static struct fst #ifdef FEAT_TERMINAL {"term_getattr", 2, 2, f_term_getattr}, {"term_getjob", 1, 1, f_term_getjob}, - {"term_getline", 2, 2, f_term_getline}, + {"term_getline", 1, 2, f_term_getline}, {"term_getsize", 1, 1, f_term_getsize}, {"term_list", 0, 0, f_term_list}, - {"term_scrape", 2, 2, f_term_scrape}, + {"term_scrape", 1, 2, f_term_scrape}, {"term_sendkeys", 2, 2, f_term_sendkeys}, {"term_start", 1, 2, f_term_start}, {"term_wait", 1, 1, f_term_wait}, diff --git a/src/terminal.c b/src/terminal.c --- a/src/terminal.c +++ b/src/terminal.c @@ -53,6 +53,7 @@ * :term <24x80> vim notes.txt * - To set BS correctly, check get_stty(); Pass the fd of the pty. * - do not store terminal window in viminfo. Or prefix term:// ? + * - add term_getcursor() - return cursor position: [row, col, visible] * - add a character in :ls output * - add 't' to mode() * - when closing window and job has not ended, make terminal hidden? @@ -120,7 +121,7 @@ struct terminal_S { garray_T tl_scrollback; int tl_scrollback_scrolled; - pos_T tl_cursor; + VTermPos tl_cursor_pos; int tl_cursor_visible; }; @@ -1020,20 +1021,16 @@ handle_movecursor( { term_T *term = (term_T *)user; win_T *wp; - int is_current = FALSE; + + term->tl_cursor_pos = pos; + term->tl_cursor_visible = visible; FOR_ALL_WINDOWS(wp) { if (wp->w_buffer == term->tl_buffer) - { position_cursor(wp, &pos); - if (wp == curwin) - is_current = TRUE; - } } - - term->tl_cursor_visible = visible; - if (is_current) + if (term->tl_buffer == curbuf) { may_toggle_cursor(term); update_cursor(term, TRUE); @@ -1723,7 +1720,10 @@ f_term_getline(typval_T *argvars, typval if (buf == NULL) return; term = buf->b_term; - row = (int)get_tv_number(&argvars[1]); + if (argvars[1].v_type == VAR_UNKNOWN) + row = term->tl_cursor_pos.row; + else + row = (int)get_tv_number(&argvars[1]); if (term->tl_vterm == NULL) { @@ -1814,7 +1814,10 @@ f_term_scrape(typval_T *argvars, typval_ screen = vterm_obtain_screen(term->tl_vterm); l = rettv->vval.v_list; - pos.row = (int)get_tv_number(&argvars[1]); + if (argvars[1].v_type == VAR_UNKNOWN) + pos.row = term->tl_cursor_pos.row; + else + pos.row = (int)get_tv_number(&argvars[1]); for (pos.col = 0; pos.col < term->tl_cols; ) { dict_T *dcell; diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -770,6 +770,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 817, +/**/ 816, /**/ 815,