diff src/terminal.c @ 11876:3704ca24c9a2 v8.0.0818

patch 8.0.0818: cannot get the cursor position of a terminal commit https://github.com/vim/vim/commit/97870002d30a9846374d1ff7d73fbef351046f20 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 30 18:28:38 2017 +0200 patch 8.0.0818: cannot get the cursor position of a terminal Problem: Cannot get the cursor position of a terminal. Solution: Add term_getcursor().
author Christian Brabandt <cb@256bit.org>
date Sun, 30 Jul 2017 18:30:05 +0200
parents d444e087b8fd
children a83b19a8d7e4
line wrap: on
line diff
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -53,7 +53,6 @@
  *      :term <24x80> <close> 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?
@@ -1637,6 +1636,24 @@ set_ref_in_term(int copyID)
 }
 
 /*
+ * Get the buffer from the first argument in "argvars".
+ * Returns NULL when the buffer is not for a terminal window.
+ */
+    static buf_T *
+term_get_buf(typval_T *argvars)
+{
+    buf_T *buf;
+
+    (void)get_tv_number(&argvars[0]);	    /* issue errmsg if type error */
+    ++emsg_off;
+    buf = get_buf_tv(&argvars[0], FALSE);
+    --emsg_off;
+    if (buf == NULL || buf->b_term == NULL)
+	return NULL;
+    return buf;
+}
+
+/*
  * "term_getattr(attr, name)" function
  */
     void
@@ -1671,21 +1688,23 @@ f_term_getattr(typval_T *argvars, typval
 }
 
 /*
- * Get the buffer from the first argument in "argvars".
- * Returns NULL when the buffer is not for a terminal window.
+ * "term_getcursor(buf)" function
  */
-    static buf_T *
-term_get_buf(typval_T *argvars)
+    void
+f_term_getcursor(typval_T *argvars, typval_T *rettv)
 {
-    buf_T *buf;
+    buf_T	*buf = term_get_buf(argvars);
+    list_T	*l;
 
-    (void)get_tv_number(&argvars[0]);	    /* issue errmsg if type error */
-    ++emsg_off;
-    buf = get_buf_tv(&argvars[0], FALSE);
-    --emsg_off;
-    if (buf == NULL || buf->b_term == NULL)
-	return NULL;
-    return buf;
+    if (rettv_list_alloc(rettv) == FAIL)
+	return;
+    if (buf == NULL)
+	return;
+
+    l = rettv->vval.v_list;
+    list_append_number(l, buf->b_term->tl_cursor_pos.row);
+    list_append_number(l, buf->b_term->tl_cursor_pos.col);
+    list_append_number(l, buf->b_term->tl_cursor_visible);
 }
 
 /*