|
53 | 53 | * :term <24x80> <close> vim notes.txt |
54 | 54 | * - To set BS correctly, check get_stty(); Pass the fd of the pty. |
55 | 55 | * - do not store terminal window in viminfo. Or prefix term:// ? |
56 | | - * - add term_getcursor() - return cursor position: [row, col, visible] |
57 | 56 | * - add a character in :ls output |
58 | 57 | * - add 't' to mode() |
59 | 58 | * - when closing window and job has not ended, make terminal hidden? |
@@ -1636,6 +1635,24 @@ set_ref_in_term(int copyID) |
1636 | 1635 | return abort; |
1637 | 1636 | } |
1638 | 1637 |
|
| 1638 | +/* |
| 1639 | + * Get the buffer from the first argument in "argvars". |
| 1640 | + * Returns NULL when the buffer is not for a terminal window. |
| 1641 | + */ |
| 1642 | + static buf_T * |
| 1643 | +term_get_buf(typval_T *argvars) |
| 1644 | +{ |
| 1645 | + buf_T *buf; |
| 1646 | + |
| 1647 | + (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ |
| 1648 | + ++emsg_off; |
| 1649 | + buf = get_buf_tv(&argvars[0], FALSE); |
| 1650 | + --emsg_off; |
| 1651 | + if (buf == NULL || buf->b_term == NULL) |
| 1652 | + return NULL; |
| 1653 | + return buf; |
| 1654 | +} |
| 1655 | + |
1639 | 1656 | /* |
1640 | 1657 | * "term_getattr(attr, name)" function |
1641 | 1658 | */ |
@@ -1671,21 +1688,23 @@ f_term_getattr(typval_T *argvars, typval_T *rettv) |
1671 | 1688 | } |
1672 | 1689 |
|
1673 | 1690 | /* |
1674 | | - * Get the buffer from the first argument in "argvars". |
1675 | | - * Returns NULL when the buffer is not for a terminal window. |
| 1691 | + * "term_getcursor(buf)" function |
1676 | 1692 | */ |
1677 | | - static buf_T * |
1678 | | -term_get_buf(typval_T *argvars) |
| 1693 | + void |
| 1694 | +f_term_getcursor(typval_T *argvars, typval_T *rettv) |
1679 | 1695 | { |
1680 | | - buf_T *buf; |
| 1696 | + buf_T *buf = term_get_buf(argvars); |
| 1697 | + list_T *l; |
1681 | 1698 |
|
1682 | | - (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ |
1683 | | - ++emsg_off; |
1684 | | - buf = get_buf_tv(&argvars[0], FALSE); |
1685 | | - --emsg_off; |
1686 | | - if (buf == NULL || buf->b_term == NULL) |
1687 | | - return NULL; |
1688 | | - return buf; |
| 1699 | + if (rettv_list_alloc(rettv) == FAIL) |
| 1700 | + return; |
| 1701 | + if (buf == NULL) |
| 1702 | + return; |
| 1703 | + |
| 1704 | + l = rettv->vval.v_list; |
| 1705 | + list_append_number(l, buf->b_term->tl_cursor_pos.row); |
| 1706 | + list_append_number(l, buf->b_term->tl_cursor_pos.col); |
| 1707 | + list_append_number(l, buf->b_term->tl_cursor_visible); |
1689 | 1708 | } |
1690 | 1709 |
|
1691 | 1710 | /* |
|
0 commit comments