Skip to content

Commit c6df10e

Browse files
committed
patch 8.0.0804: terminal window functions not yet implemented
Problem: Terminal window functions not yet implemented. Solution: Implement several functions. Add a first test. (Yasuhiro Matsumoto, closes #1871)
1 parent 70229f9 commit c6df10e

9 files changed

Lines changed: 577 additions & 89 deletions

File tree

runtime/doc/eval.txt

Lines changed: 71 additions & 19 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 28
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 29
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2369,12 +2369,15 @@ tagfiles() List tags files used
23692369
tan({expr}) Float tangent of {expr}
23702370
tanh({expr}) Float hyperbolic tangent of {expr}
23712371
tempname() String name for a temporary file
2372-
term_getsize() Dict get the size of a terminal
2373-
term_open() Job open a terminal window and run a job
2374-
term_scrape() List inspect terminal screen
2375-
term_sendkeys() Number send keystrokes to a terminal
2376-
term_setsize() Number set the size of a terminal
2377-
term_wait() Number wait for screen to be updated
2372+
term_getattr({attr}, {what} Number get the value of attribute {what}
2373+
term_getjob({buf}) Job get the job associated with a terminal
2374+
term_getline({buf}, {row}) String get a line of text from a terminal
2375+
term_getsize({buf}) List get the size of a terminal
2376+
term_list() List get the list of terminal buffers
2377+
term_scrape({buf}, {row}) List get row of a terminal screen
2378+
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
2379+
term_start({cmd}, {options}) Job open a terminal window and run a job
2380+
term_wait({buf}) Number wait for screen to be updated
23782381
test_alloc_fail({id}, {countdown}, {repeat})
23792382
none make memory allocation fail
23802383
test_autochdir() none enable 'autochdir' during startup
@@ -7898,23 +7901,72 @@ tempname() *tempname()* *temp-file-name*
78987901
For MS-Windows forward slashes are used when the 'shellslash'
78997902
option is set or when 'shellcmdflag' starts with '-'.
79007903

7901-
term_getsize() *term_getsize()*
7902-
Get the size of a terminal. NOT IMPLEMENTED YET
7904+
term_getattr({attr}, {what}) *term_getattr()*
7905+
Given {attr}, a value returned by term_scrape() in the "attr"
7906+
item, return whether {what} is on. {what} can be one of:
7907+
bold
7908+
italic
7909+
underline
7910+
strike
7911+
reverse
79037912

7904-
term_open() *term_open()*
7905-
Open a terminal window and run a job. NOT IMPLEMENTED YET
7913+
term_getjob({buf}) *term_getjob()*
7914+
Get the Job associated with terminal window {buf}.
7915+
{buf} is used as with |term_getsize()|.
79067916

7907-
term_scrape() *term_scrape()*
7908-
Inspect terminal screen. NOT IMPLEMENTED YET
7917+
term_getline({buf}, {row}) *term_getline()*
7918+
Get a line of text from the terminal window of {buf}.
7919+
{buf} is used as with |term_getsize()|.
79097920

7910-
term_sendkeys() *term_sendkeys()*
7911-
Send keystrokes to a terminal. NOT IMPLEMENTED YET
7921+
The first line has {row} zero. When {row} is invalid an empty
7922+
string is returned.
79127923

7913-
term_setsize() *term_setsize()*
7914-
Set the size of a terminal. NOT IMPLEMENTED YET
7924+
term_getsize({buf}) *term_getsize()*
7925+
Get the size of terminal {buf}. Returns a list with two
7926+
numbers: [rows, cols]. This is the size of the terminal, not
7927+
the window containing the terminal.
79157928

7916-
term_wait() *term_wait()*
7917-
Wait for screen to be updated. NOT IMPLEMENTED YET
7929+
{buf} must be the buffer number of a terminal window. If the
7930+
buffer does not exist or is not a terminal window, an empty
7931+
list is returned.
7932+
7933+
term_list(}) *term_list()*
7934+
Return a list with the buffer numbers of all buffers for
7935+
terminal windows.
7936+
7937+
term_scrape({buf}, {row}) *term_scrape()*
7938+
Get the contents of {row} of terminal screen of {buf}.
7939+
For {buf} see |term_getsize()|.
7940+
7941+
The first {row} is zero. When {row} is invalid an empty list
7942+
is returned.
7943+
7944+
Return a List containing a Dict for each screen cell:
7945+
"chars" character(s) at the cell
7946+
"fg" foreground color as #rrggbb
7947+
"bg" background color as #rrggbb
7948+
"attr" attributes of the cell, use term_getattr()
7949+
to get the individual flags
7950+
"width" cell width: 1 or 2
7951+
7952+
term_sendkeys({buf}, {keys}) *term_sendkeys()*
7953+
Send keystrokes {keys} to terminal {buf}.
7954+
{buf} is used as with |term_getsize()|.
7955+
7956+
{keys} are translated as key sequences. For example, "\<c-x>"
7957+
means the character CTRL-X.
7958+
7959+
term_start({cmd}, {options}) *term_start()*
7960+
Open a terminal window and run {cmd} in it.
7961+
7962+
Returns the buffer number of the terminal window.
7963+
When opening the window fails zero is returned.
7964+
7965+
{options} are not implemented yet.
7966+
7967+
term_wait({buf}) *term_wait()*
7968+
Wait for pending updates of {buf} to be handled.
7969+
{buf} is used as with |term_getsize()|.
79187970

79197971
test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()*
79207972
This is for testing: If the memory allocation with {id} is

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,7 @@ test_arglist \
22562256
test_tagjump \
22572257
test_taglist \
22582258
test_tcl \
2259+
test_terminal \
22592260
test_textobjects \
22602261
test_timers \
22612262
test_true_false \

src/evalfunc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,17 @@ static struct fst
830830
{"tanh", 1, 1, f_tanh},
831831
#endif
832832
{"tempname", 0, 0, f_tempname},
833+
#ifdef FEAT_TERMINAL
834+
{"term_getattr", 2, 2, f_term_getattr},
835+
{"term_getjob", 1, 1, f_term_getjob},
836+
{"term_getline", 2, 2, f_term_getline},
837+
{"term_getsize", 1, 1, f_term_getsize},
838+
{"term_list", 0, 0, f_term_list},
839+
{"term_scrape", 2, 2, f_term_scrape},
840+
{"term_sendkeys", 2, 2, f_term_sendkeys},
841+
{"term_start", 1, 2, f_term_start},
842+
{"term_wait", 1, 1, f_term_wait},
843+
#endif
833844
{"test_alloc_fail", 3, 3, f_test_alloc_fail},
834845
{"test_autochdir", 0, 0, f_test_autochdir},
835846
{"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now},
@@ -1540,7 +1551,7 @@ buflist_find_by_name(char_u *name, int curtab_only)
15401551
/*
15411552
* Get buffer by number or pattern.
15421553
*/
1543-
static buf_T *
1554+
buf_T *
15441555
get_buf_tv(typval_T *tv, int curtab_only)
15451556
{
15461557
char_u *name = tv->vval.v_string;

src/proto/evalfunc.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* evalfunc.c */
2+
buf_T* get_buf_tv(typval_T *tv, int curtab_only);
23
char_u *get_function_name(expand_T *xp, int idx);
34
char_u *get_expr_name(expand_T *xp, int idx);
45
int find_internal_func(char_u *name);

src/proto/terminal.pro

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ void ex_terminal(exarg_T *eap);
33
void free_terminal(buf_T *buf);
44
void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
55
int terminal_loop(void);
6+
void term_job_ended(job_T *job);
67
void term_channel_closed(channel_T *ch);
78
int term_update_window(win_T *wp);
89
int term_is_finished(buf_T *buf);
910
void term_change_in_curbuf(void);
1011
int term_get_attr(buf_T *buf, linenr_T lnum, int col);
1112
char_u *term_get_status_text(term_T *term);
1213
int set_ref_in_term(int copyID);
14+
void f_term_getattr(typval_T *argvars, typval_T *rettv);
15+
void f_term_getjob(typval_T *argvars, typval_T *rettv);
16+
void f_term_getline(typval_T *argvars, typval_T *rettv);
17+
void f_term_getsize(typval_T *argvars, typval_T *rettv);
18+
void f_term_list(typval_T *argvars, typval_T *rettv);
19+
void f_term_start(typval_T *argvars, typval_T *rettv);
20+
void f_term_scrape(typval_T *argvars, typval_T *rettv);
21+
void f_term_sendkeys(typval_T *argvars, typval_T *rettv);
22+
void f_term_wait(typval_T *argvars, typval_T *rettv);
1323
/* vim: set ft=c : */

0 commit comments

Comments
 (0)