blob: 862a669440493e82b9cd4723789154708a2dedba [file] [log] [blame]
Bram Moolenaare4f25e42017-07-07 11:54:15 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Terminal window support, see ":help :terminal".
12 *
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020013 * There are three parts:
14 * 1. Generic code for all systems.
Bram Moolenaarb13501f2017-07-22 22:32:56 +020015 * Uses libvterm for the terminal emulator.
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020016 * 2. The MS-Windows implementation.
Bram Moolenaarb13501f2017-07-22 22:32:56 +020017 * Uses winpty.
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020018 * 3. The Unix-like implementation.
Bram Moolenaarb13501f2017-07-22 22:32:56 +020019 * Uses pseudo-tty's (pty's).
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020020 *
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of
22 * that library is in the libvterm directory.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020023 *
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020024 * When a terminal window is opened, a job is started that will be connected to
25 * the terminal emulator.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020026 *
27 * If the terminal window has keyboard focus, typed keys are converted to the
28 * terminal encoding and writting to the job over a channel.
29 *
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020030 * If the job produces output, it is written to the terminal emulator. The
31 * terminal emulator invokes callbacks when its screen content changes. The
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
33 * while, if the terminal window is visible, the screen contents is drawn.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020034 *
35 * TODO:
Bram Moolenaareeac6772017-07-23 15:48:37 +020036 * - color for GUI
37 * - color for 'termguicolors'
38 * - cursor flickers when moving the cursor
Bram Moolenaare4f25e42017-07-07 11:54:15 +020039 * - set buffer options to be scratch, hidden, nomodifiable, etc.
40 * - set buffer name to command, add (1) to avoid duplicates.
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020041 * - Add a scrollback buffer (contains lines to scroll off the top).
42 * Can use the buf_T lines, store attributes somewhere else?
43 * - When the job ends:
44 * - Write "-- JOB ENDED --" in the terminal.
45 * - Put the terminal contents in the scrollback buffer.
46 * - Free the terminal emulator.
47 * - Display the scrollback buffer (but with attributes).
48 * Make the buffer not modifiable, drop attributes when making changes.
Bram Moolenaar938783d2017-07-16 20:13:26 +020049 * - when closing window and job has not ended, make terminal hidden?
Bram Moolenaar9f1f49b2017-07-22 18:14:17 +020050 * - don't allow exiting Vim when a terminal is still running a job
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020051 * - use win_del_lines() to make scroll-up efficient.
Bram Moolenaar938783d2017-07-16 20:13:26 +020052 * - command line completion for :terminal
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020053 * - add test for giving error for invalid 'termsize' value.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020054 * - support minimal size when 'termsize' is "rows*cols".
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020055 * - support minimal size when 'termsize' is empty?
Bram Moolenaar5a1feb82017-07-22 18:04:08 +020056 * - implement "term" for job_start(): more job options when starting a
57 * terminal.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020058 * - implement ":buf {term-buf-name}"
Bram Moolenaar96ca27a2017-07-17 23:20:24 +020059 * - implement term_list() list of buffers with a terminal
60 * - implement term_getsize(buf)
61 * - implement term_setsize(buf)
62 * - implement term_sendkeys(buf, keys) send keystrokes to a terminal
63 * - implement term_wait(buf) wait for screen to be updated
64 * - implement term_scrape(buf, row) inspect terminal screen
65 * - implement term_open(command, options) open terminal window
66 * - implement term_getjob(buf)
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +020067 * - implement 'termkey'
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020068 * - when 'encoding' is not utf-8, or the job is using another encoding, setup
69 * conversions.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020070 */
71
72#include "vim.h"
73
74#ifdef FEAT_TERMINAL
75
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020076#ifdef WIN3264
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020077# define MIN(x,y) (x < y ? x : y)
78# define MAX(x,y) (x > y ? x : y)
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020079#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020080
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020081#include "libvterm/include/vterm.h"
82
Bram Moolenaare4f25e42017-07-07 11:54:15 +020083/* typedef term_T in structs.h */
84struct terminal_S {
85 term_T *tl_next;
86
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020087#ifdef WIN3264
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020088 void *tl_winpty_config;
89 void *tl_winpty;
Bram Moolenaar8c0095c2017-07-18 22:53:21 +020090#endif
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020091 VTerm *tl_vterm;
Bram Moolenaare4f25e42017-07-07 11:54:15 +020092 job_T *tl_job;
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +020093 buf_T *tl_buffer;
Bram Moolenaare4f25e42017-07-07 11:54:15 +020094
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +020095 /* last known vterm size */
96 int tl_rows;
97 int tl_cols;
98 /* vterm size does not follow window size */
99 int tl_rows_fixed;
100 int tl_cols_fixed;
101
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200102 /* Range of screen rows to update. Zero based. */
103 int tl_dirty_row_start; /* -1 if nothing dirty */
104 int tl_dirty_row_end; /* row below last one to update */
105
106 pos_T tl_cursor;
107};
108
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200109/*
110 * List of all active terminals.
111 */
112static term_T *first_term = NULL;
113
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200114
115#define MAX_ROW 999999 /* used for tl_dirty_row_end to update all rows */
116#define KEY_BUF_LEN 200
117
118/*
119 * Functions with separate implementation for MS-Windows and Unix-like systems.
120 */
121static int term_and_job_init(term_T *term, int rows, int cols, char_u *cmd);
122static void term_free(term_T *term);
123
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200124/**************************************
125 * 1. Generic code for all systems.
126 */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200127
128/*
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200129 * Determine the terminal size from 'termsize' and the current window.
130 * Assumes term->tl_rows and term->tl_cols are zero.
131 */
132 static void
133set_term_and_win_size(term_T *term)
134{
135 if (*curwin->w_p_tms != NUL)
136 {
137 char_u *p = vim_strchr(curwin->w_p_tms, 'x') + 1;
138
139 term->tl_rows = atoi((char *)curwin->w_p_tms);
140 term->tl_cols = atoi((char *)p);
141 }
142 if (term->tl_rows == 0)
143 term->tl_rows = curwin->w_height;
144 else
145 {
146 win_setheight_win(term->tl_rows, curwin);
147 term->tl_rows_fixed = TRUE;
148 }
149 if (term->tl_cols == 0)
150 term->tl_cols = curwin->w_width;
151 else
152 {
153 win_setwidth_win(term->tl_cols, curwin);
154 term->tl_cols_fixed = TRUE;
155 }
156}
157
158/*
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200159 * ":terminal": open a terminal window and execute a job in it.
160 */
161 void
162ex_terminal(exarg_T *eap)
163{
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200164 exarg_T split_ea;
165 win_T *old_curwin = curwin;
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200166 term_T *term;
Bram Moolenaare173fd02017-07-22 19:03:32 +0200167 char_u *cmd = eap->arg;
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200168
169 if (check_restricted() || check_secure())
170 return;
171
172 term = (term_T *)alloc_clear(sizeof(term_T));
173 if (term == NULL)
174 return;
175 term->tl_dirty_row_end = MAX_ROW;
176
177 /* Open a new window or tab. */
178 vim_memset(&split_ea, 0, sizeof(split_ea));
179 split_ea.cmdidx = CMD_new;
180 split_ea.cmd = (char_u *)"new";
181 split_ea.arg = (char_u *)"";
182 ex_splitview(&split_ea);
183 if (curwin == old_curwin)
184 {
185 /* split failed */
186 vim_free(term);
187 return;
188 }
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +0200189 term->tl_buffer = curbuf;
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200190 curbuf->b_term = term;
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200191
192 /* Link the new terminal in the list of active terminals. */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200193 term->tl_next = first_term;
194 first_term = term;
195
196 /* TODO: set buffer type, hidden, etc. */
197
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200198 set_term_and_win_size(term);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200199
Bram Moolenaare173fd02017-07-22 19:03:32 +0200200 if (cmd == NULL || *cmd == NUL)
201 cmd = p_sh;
202
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200203 /* System dependent: setup the vterm and start the job in it. */
Bram Moolenaare173fd02017-07-22 19:03:32 +0200204 if (term_and_job_init(term, term->tl_rows, term->tl_cols, cmd) == OK)
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200205 {
206 /* store the size we ended up with */
207 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200208 }
209 else
210 {
Bram Moolenaar61a66052017-07-22 18:39:00 +0200211 free_terminal(term);
212 curbuf->b_term = NULL;
213
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200214 /* Wiping out the buffer will also close the window and call
215 * free_terminal(). */
Bram Moolenaar96ca27a2017-07-17 23:20:24 +0200216 do_buffer(DOBUF_WIPE, DOBUF_CURRENT, FORWARD, 0, TRUE);
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200217 }
Bram Moolenaar96ca27a2017-07-17 23:20:24 +0200218
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200219 /* TODO: Setup pty, see mch_call_shell(). */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200220}
221
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +0200222/*
Bram Moolenaar96ca27a2017-07-17 23:20:24 +0200223 * Free a terminal and everything it refers to.
224 * Kills the job if there is one.
225 * Called when wiping out a buffer.
226 */
227 void
228free_terminal(term_T *term)
229{
230 term_T *tp;
231
232 if (term == NULL)
233 return;
234 if (first_term == term)
235 first_term = term->tl_next;
236 else
237 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
238 if (tp->tl_next == term)
239 {
240 tp->tl_next = term->tl_next;
241 break;
242 }
243
244 if (term->tl_job != NULL)
245 {
Bram Moolenaar61a66052017-07-22 18:39:00 +0200246 if (term->tl_job->jv_status != JOB_ENDED
247 && term->tl_job->jv_status != JOB_FAILED)
Bram Moolenaar96ca27a2017-07-17 23:20:24 +0200248 job_stop(term->tl_job, NULL, "kill");
249 job_unref(term->tl_job);
250 }
251
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200252 term_free(term);
Bram Moolenaar96ca27a2017-07-17 23:20:24 +0200253 vim_free(term);
254}
255
256/*
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200257 * Write job output "msg[len]" to the vterm.
258 */
259 static void
260term_write_job_output(term_T *term, char_u *msg, size_t len)
261{
262 VTerm *vterm = term->tl_vterm;
263 char_u *p;
264 size_t done;
265 size_t len_now;
266
267 for (done = 0; done < len; done += len_now)
268 {
269 for (p = msg + done; p < msg + len; )
270 {
271 if (*p == NL)
272 break;
273 p += utf_ptr2len_len(p, len - (p - msg));
274 }
275 len_now = p - msg - done;
276 vterm_input_write(vterm, (char *)msg + done, len_now);
277 if (p < msg + len && *p == NL)
278 {
279 /* Convert NL to CR-NL, that appears to work best. */
280 vterm_input_write(vterm, "\r\n", 2);
281 ++len_now;
282 }
283 }
284
285 /* this invokes the damage callbacks */
286 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
287}
288
289/*
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +0200290 * Invoked when "msg" output from a job was received. Write it to the terminal
291 * of "buffer".
292 */
293 void
294write_to_term(buf_T *buffer, char_u *msg, channel_T *channel)
295{
296 size_t len = STRLEN(msg);
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200297 term_T *term = buffer->b_term;
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +0200298
299 ch_logn(channel, "writing %d bytes to terminal", (int)len);
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200300 term_write_job_output(term, msg, len);
Bram Moolenaarcb8bbe92017-07-16 13:48:22 +0200301
302 /* TODO: only update once in a while. */
303 update_screen(0);
304 setcursor();
305 out_flush();
306}
307
308/*
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200309 * Convert typed key "c" into bytes to send to the job.
310 * Return the number of bytes in "buf".
311 */
312 static int
313term_convert_key(int c, char *buf)
314{
315 VTerm *vterm = curbuf->b_term->tl_vterm;
316 VTermKey key = VTERM_KEY_NONE;
317 VTermModifier mod = VTERM_MOD_NONE;
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200318
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200319 switch (c)
320 {
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200321 case CAR: key = VTERM_KEY_ENTER; break;
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200322 case ESC: key = VTERM_KEY_ESCAPE; break;
Bram Moolenaare906ae82017-07-21 21:10:01 +0200323 /* VTERM_KEY_BACKSPACE becomes 0x7f DEL */
324 case K_BS: c = BS; break;
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200325 case K_DEL: key = VTERM_KEY_DEL; break;
326 case K_DOWN: key = VTERM_KEY_DOWN; break;
327 case K_END: key = VTERM_KEY_END; break;
328 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
329 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
330 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
331 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
332 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
333 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
334 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
335 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
336 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
337 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
338 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
339 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
340 case K_HOME: key = VTERM_KEY_HOME; break;
341 case K_INS: key = VTERM_KEY_INS; break;
342 case K_K0: key = VTERM_KEY_KP_0; break;
343 case K_K1: key = VTERM_KEY_KP_1; break;
344 case K_K2: key = VTERM_KEY_KP_2; break;
345 case K_K3: key = VTERM_KEY_KP_3; break;
346 case K_K4: key = VTERM_KEY_KP_4; break;
347 case K_K5: key = VTERM_KEY_KP_5; break;
348 case K_K6: key = VTERM_KEY_KP_6; break;
349 case K_K7: key = VTERM_KEY_KP_7; break;
350 case K_K8: key = VTERM_KEY_KP_8; break;
351 case K_K9: key = VTERM_KEY_KP_9; break;
352 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */
353 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
354 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */
355 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
356 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */
357 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */
358 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
359 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
360 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */
361 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */
362 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
363 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
364 case K_LEFT: key = VTERM_KEY_LEFT; break;
365 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
366 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
367 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
368 case K_UP: key = VTERM_KEY_UP; break;
369 case TAB: key = VTERM_KEY_TAB; break;
Bram Moolenaare825d8b2017-07-19 23:20:19 +0200370
371 case K_MOUSEUP: /* TODO */ break;
372 case K_MOUSEDOWN: /* TODO */ break;
373 case K_MOUSELEFT: /* TODO */ break;
374 case K_MOUSERIGHT: /* TODO */ break;
375
376 case K_LEFTMOUSE: /* TODO */ break;
377 case K_LEFTMOUSE_NM: /* TODO */ break;
378 case K_LEFTDRAG: /* TODO */ break;
379 case K_LEFTRELEASE: /* TODO */ break;
380 case K_LEFTRELEASE_NM: /* TODO */ break;
381 case K_MIDDLEMOUSE: /* TODO */ break;
382 case K_MIDDLEDRAG: /* TODO */ break;
383 case K_MIDDLERELEASE: /* TODO */ break;
384 case K_RIGHTMOUSE: /* TODO */ break;
385 case K_RIGHTDRAG: /* TODO */ break;
386 case K_RIGHTRELEASE: /* TODO */ break;
387 case K_X1MOUSE: /* TODO */ break;
388 case K_X1DRAG: /* TODO */ break;
389 case K_X1RELEASE: /* TODO */ break;
390 case K_X2MOUSE: /* TODO */ break;
391 case K_X2DRAG: /* TODO */ break;
392 case K_X2RELEASE: /* TODO */ break;
393
394 /* TODO: handle all special keys and modifiers that terminal_loop()
395 * does not handle. */
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200396 }
397
398 /*
399 * Convert special keys to vterm keys:
400 * - Write keys to vterm: vterm_keyboard_key()
401 * - Write output to channel.
402 */
403 if (key != VTERM_KEY_NONE)
404 /* Special key, let vterm convert it. */
405 vterm_keyboard_key(vterm, key, mod);
406 else
407 /* Normal character, let vterm convert it. */
408 vterm_keyboard_unichar(vterm, c, mod);
409
410 /* Read back the converted escape sequence. */
411 return vterm_output_read(vterm, buf, KEY_BUF_LEN);
412}
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200413
Bram Moolenaar938783d2017-07-16 20:13:26 +0200414/*
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200415 * Wait for input and send it to the job.
416 * Return when the start of a CTRL-W command is typed or anything else that
417 * should be handled as a Normal mode command.
418 */
419 void
420terminal_loop(void)
421{
422 char buf[KEY_BUF_LEN];
423 int c;
424 size_t len;
425 static int mouse_was_outside = FALSE;
426 int dragging_outside = FALSE;
427
428 for (;;)
429 {
430 /* TODO: skip screen update when handling a sequence of keys. */
431 update_screen(0);
432 setcursor();
433 out_flush();
434 ++no_mapping;
435 ++allow_keys;
436 got_int = FALSE;
437 c = vgetc();
438 --no_mapping;
439 --allow_keys;
440
441 /* Catch keys that need to be handled as in Normal mode. */
442 switch (c)
443 {
444 case Ctrl_W:
445 case NUL:
446 case K_ZERO:
447 stuffcharReadbuff(c);
448 return;
449
450 case K_IGNORE: continue;
451
452 case K_LEFTDRAG:
453 case K_MIDDLEDRAG:
454 case K_RIGHTDRAG:
455 case K_X1DRAG:
456 case K_X2DRAG:
457 dragging_outside = mouse_was_outside;
458 /* FALLTHROUGH */
459 case K_LEFTMOUSE:
460 case K_LEFTMOUSE_NM:
461 case K_LEFTRELEASE:
462 case K_LEFTRELEASE_NM:
463 case K_MIDDLEMOUSE:
464 case K_MIDDLERELEASE:
465 case K_RIGHTMOUSE:
466 case K_RIGHTRELEASE:
467 case K_X1MOUSE:
468 case K_X1RELEASE:
469 case K_X2MOUSE:
470 case K_X2RELEASE:
471 if (mouse_row < W_WINROW(curwin)
472 || mouse_row >= (W_WINROW(curwin) + curwin->w_height)
473 || mouse_col < W_WINCOL(curwin)
474 || mouse_col >= W_ENDCOL(curwin)
475 || dragging_outside)
476 {
477 /* click outside the current window */
478 stuffcharReadbuff(c);
479 mouse_was_outside = TRUE;
480 return;
481 }
482 }
483 mouse_was_outside = FALSE;
484
485 /* Convert the typed key to a sequence of bytes for the job. */
486 len = term_convert_key(c, buf);
487 if (len > 0)
488 /* TODO: if FAIL is returned, stop? */
489 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
490 (char_u *)buf, len, NULL);
491 }
492}
493
494 static void
495position_cursor(win_T *wp, VTermPos *pos)
496{
497 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
498 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
499}
500
501static int handle_damage(VTermRect rect, void *user);
502static int handle_moverect(VTermRect dest, VTermRect src, void *user);
503static int handle_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user);
504static int handle_resize(int rows, int cols, void *user);
505
506static VTermScreenCallbacks screen_callbacks = {
507 handle_damage, /* damage */
508 handle_moverect, /* moverect */
509 handle_movecursor, /* movecursor */
510 NULL, /* settermprop */
511 NULL, /* bell */
512 handle_resize, /* resize */
513 NULL, /* sb_pushline */
514 NULL /* sb_popline */
515};
516
517 static int
518handle_damage(VTermRect rect, void *user)
519{
520 term_T *term = (term_T *)user;
521
522 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row);
523 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
524 redraw_buf_later(term->tl_buffer, NOT_VALID);
525 return 1;
526}
527
528 static int
529handle_moverect(VTermRect dest UNUSED, VTermRect src UNUSED, void *user)
530{
531 term_T *term = (term_T *)user;
532
533 /* TODO */
534 redraw_buf_later(term->tl_buffer, NOT_VALID);
535 return 1;
536}
537
538 static int
539handle_movecursor(
540 VTermPos pos,
541 VTermPos oldpos UNUSED,
542 int visible UNUSED,
543 void *user)
544{
545 term_T *term = (term_T *)user;
546 win_T *wp;
547 int is_current = FALSE;
548
549 FOR_ALL_WINDOWS(wp)
550 {
551 if (wp->w_buffer == term->tl_buffer)
552 {
553 position_cursor(wp, &pos);
554 if (wp == curwin)
555 is_current = TRUE;
556 }
557 }
558
559 if (is_current)
560 {
561 setcursor();
562 out_flush();
563 }
564
565 return 1;
566}
567
568/*
569 * The job running in the terminal resized the terminal.
570 */
571 static int
572handle_resize(int rows, int cols, void *user)
573{
574 term_T *term = (term_T *)user;
575 win_T *wp;
576
577 term->tl_rows = rows;
578 term->tl_cols = cols;
579 FOR_ALL_WINDOWS(wp)
580 {
581 if (wp->w_buffer == term->tl_buffer)
582 {
583 win_setheight_win(rows, wp);
584 win_setwidth_win(cols, wp);
585 }
586 }
587
588 redraw_buf_later(term->tl_buffer, NOT_VALID);
589 return 1;
590}
591
592/*
Bram Moolenaareeac6772017-07-23 15:48:37 +0200593 * Reverse engineer the RGB value into a cterm color index.
594 * First color is 1. Return 0 if no match found.
595 */
596 static int
597color2index(VTermColor *color)
598{
599 int red = color->red;
600 int blue = color->blue;
601 int green = color->green;
602
603 if (red == 0)
604 {
605 if (green == 0)
606 {
607 if (blue == 0)
608 return 1; /* black */
609 if (blue == 224)
610 return 5; /* blue */
611 }
612 else if (green == 224)
613 {
614 if (blue == 0)
615 return 3; /* green */
616 if (blue == 224)
617 return 7; /* cyan */
618 }
619 }
620 else if (red == 224)
621 {
622 if (green == 0)
623 {
624 if (blue == 0)
625 return 2; /* red */
626 if (blue == 224)
627 return 6; /* magenta */
628 }
629 else if (green == 224)
630 {
631 if (blue == 0)
632 return 4; /* yellow */
633 if (blue == 224)
634 return 8; /* white */
635 }
636 }
637 else if (red == 128)
638 {
639 if (green == 128 && blue == 128)
640 return 9; /* high intensity bladk */
641 }
642 else if (red == 255)
643 {
644 if (green == 64)
645 {
646 if (blue == 64)
647 return 10; /* high intensity red */
648 if (blue == 255)
649 return 14; /* high intensity magenta */
650 }
651 else if (green == 255)
652 {
653 if (blue == 64)
654 return 12; /* high intensity yellow */
655 if (blue == 255)
656 return 16; /* high intensity white */
657 }
658 }
659 else if (red == 64)
660 {
661 if (green == 64)
662 {
663 if (blue == 255)
664 return 13; /* high intensity blue */
665 }
666 else if (green == 255)
667 {
668 if (blue == 64)
669 return 11; /* high intensity green */
670 if (blue == 255)
671 return 15; /* high intensity cyan */
672 }
673 }
674 if (t_colors >= 256)
675 {
676 if (red == blue && red == green)
677 {
678 /* 24-color greyscale */
679 static int cutoff[23] = {
680 0x05, 0x10, 0x1B, 0x26, 0x31, 0x3C, 0x47, 0x52,
681 0x5D, 0x68, 0x73, 0x7F, 0x8A, 0x95, 0xA0, 0xAB,
682 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, 0xED, 0xF9};
683 int i;
684
685 for (i = 0; i < 23; ++i)
686 if (red < cutoff[i])
687 return i + 233;
688 return 256;
689 }
690
691 /* 216-color cube */
692 return 17 + ((red + 25) / 0x33) * 36
693 + ((green + 25) / 0x33) * 6
694 + (blue + 25) / 0x33;
695 }
696 return 0;
697}
698
699/*
700 * Convert the attributes of a vterm cell into an attribute index.
701 */
702 static int
703cell2attr(VTermScreenCell *cell)
704{
705 int attr = 0;
706
707 if (cell->attrs.bold)
708 attr |= HL_BOLD;
709 if (cell->attrs.underline)
710 attr |= HL_UNDERLINE;
711 if (cell->attrs.italic)
712 attr |= HL_ITALIC;
713 if (cell->attrs.strike)
714 attr |= HL_STANDOUT;
715 if (cell->attrs.reverse)
716 attr |= HL_INVERSE;
717 if (cell->attrs.strike)
718 attr |= HL_UNDERLINE;
719
720#ifdef FEAT_GUI
721 if (gui.in_use)
722 {
723 /* TODO */
724 }
725 else
726#endif
727#ifdef FEAT_TERMGUICOLORS
728 if (p_tgc)
729 {
730 /* TODO */
731 }
732#endif
733 {
734 return get_cterm_attr_idx(attr, color2index(&cell->fg),
735 color2index(&cell->bg));
736 }
737 return 0;
738}
739
740/*
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200741 * Called to update the window that contains the terminal.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200742 */
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200743 void
744term_update_window(win_T *wp)
Bram Moolenaar938783d2017-07-16 20:13:26 +0200745{
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200746 term_T *term = wp->w_buffer->b_term;
747 VTerm *vterm = term->tl_vterm;
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200748 VTermScreen *screen = vterm_obtain_screen(vterm);
Bram Moolenaar58556cd2017-07-20 23:04:46 +0200749 VTermState *state = vterm_obtain_state(vterm);
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200750 VTermPos pos;
Bram Moolenaar938783d2017-07-16 20:13:26 +0200751
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200752 /*
753 * If the window was resized a redraw will be triggered and we get here.
754 * Adjust the size of the vterm unless 'termsize' specifies a fixed size.
755 */
756 if ((!term->tl_rows_fixed && term->tl_rows != wp->w_height)
757 || (!term->tl_cols_fixed && term->tl_cols != wp->w_width))
Bram Moolenaarb13501f2017-07-22 22:32:56 +0200758 {
759 int rows = term->tl_rows_fixed ? term->tl_rows : wp->w_height;
760 int cols = term->tl_cols_fixed ? term->tl_cols : wp->w_width;
761
762 vterm_set_size(vterm, rows, cols);
763 ch_logn(term->tl_job->jv_channel, "Resizing terminal to %d lines",
764 rows);
765
766#if defined(UNIX)
767 /* Use an ioctl() to report the new window size to the job. */
768 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
769 {
770 int fd = -1;
771 int part;
772
773 for (part = PART_OUT; part < PART_COUNT; ++part)
774 {
775 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
776 if (isatty(fd))
777 break;
778 }
779 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
780 mch_stop_job(term->tl_job, (char_u *)"winch");
781 }
782#endif
783 }
Bram Moolenaar58556cd2017-07-20 23:04:46 +0200784
785 /* The cursor may have been moved when resizing. */
786 vterm_state_get_cursorpos(state, &pos);
787 position_cursor(wp, &pos);
788
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200789 /* TODO: Only redraw what changed. */
790 for (pos.row = 0; pos.row < wp->w_height; ++pos.row)
Bram Moolenaar938783d2017-07-16 20:13:26 +0200791 {
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200792 int off = screen_get_current_line_off();
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200793 int max_col = MIN(wp->w_width, term->tl_cols);
Bram Moolenaar938783d2017-07-16 20:13:26 +0200794
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200795 if (pos.row < term->tl_rows)
796 {
797 for (pos.col = 0; pos.col < max_col; )
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200798 {
799 VTermScreenCell cell;
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200800 int c;
Bram Moolenaar938783d2017-07-16 20:13:26 +0200801
Bram Moolenaareeac6772017-07-23 15:48:37 +0200802 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
803 vim_memset(&cell, 0, sizeof(cell));
804
805 /* TODO: composing chars */
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200806 c = cell.chars[0];
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200807 if (c == NUL)
808 {
809 ScreenLines[off] = ' ';
810 ScreenLinesUC[off] = NUL;
811 }
812 else
813 {
814#if defined(FEAT_MBYTE)
815 if (enc_utf8 && c >= 0x80)
Bram Moolenaar9f1f49b2017-07-22 18:14:17 +0200816 {
817 ScreenLines[off] = ' ';
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200818 ScreenLinesUC[off] = c;
Bram Moolenaar9f1f49b2017-07-22 18:14:17 +0200819 }
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200820 else
Bram Moolenaar9f1f49b2017-07-22 18:14:17 +0200821 {
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200822 ScreenLines[off] = c;
Bram Moolenaar9f1f49b2017-07-22 18:14:17 +0200823 ScreenLinesUC[off] = NUL;
824 }
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200825#else
826 ScreenLines[off] = c;
827#endif
828 }
Bram Moolenaareeac6772017-07-23 15:48:37 +0200829 ScreenAttrs[off] = cell2attr(&cell);
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200830
831 ++pos.col;
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200832 ++off;
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200833 if (cell.width == 2)
834 {
Bram Moolenaar9f1f49b2017-07-22 18:14:17 +0200835 ScreenLines[off] = NUL;
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200836 ScreenLinesUC[off] = NUL;
837 ++pos.col;
838 ++off;
839 }
Bram Moolenaar8c0095c2017-07-18 22:53:21 +0200840 }
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200841 }
Bram Moolenaare825d8b2017-07-19 23:20:19 +0200842 else
843 pos.col = 0;
Bram Moolenaar938783d2017-07-16 20:13:26 +0200844
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200845 screen_line(wp->w_winrow + pos.row, wp->w_wincol,
846 pos.col, wp->w_width, FALSE);
Bram Moolenaar938783d2017-07-16 20:13:26 +0200847 }
848}
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200849
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200850/*
851 * Set job options common for Unix and MS-Windows.
852 */
853 static void
854setup_job_options(jobopt_T *opt, int rows, int cols)
855{
856 clear_job_options(opt);
857 opt->jo_mode = MODE_RAW;
858 opt->jo_out_mode = MODE_RAW;
859 opt->jo_err_mode = MODE_RAW;
860 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
861 opt->jo_io[PART_OUT] = JIO_BUFFER;
862 opt->jo_io[PART_ERR] = JIO_BUFFER;
863 opt->jo_set |= JO_OUT_IO + (JO_OUT_IO << (PART_ERR - PART_OUT));
864 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
865 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
Bram Moolenaar5a1feb82017-07-22 18:04:08 +0200866 opt->jo_pty = TRUE;
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200867 opt->jo_set |= JO_OUT_BUF + (JO_OUT_BUF << (PART_ERR - PART_OUT));
868 opt->jo_term_rows = rows;
869 opt->jo_term_cols = cols;
870}
871
872/*
873 * Create a new vterm and initialize it.
874 */
875 static void
876create_vterm(term_T *term, int rows, int cols)
877{
878 VTerm *vterm;
879 VTermScreen *screen;
880
881 vterm = vterm_new(rows, cols);
882 term->tl_vterm = vterm;
883 screen = vterm_obtain_screen(vterm);
884 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
885 /* TODO: depends on 'encoding'. */
886 vterm_set_utf8(vterm, 1);
Bram Moolenaareeac6772017-07-23 15:48:37 +0200887
888 /* Vterm uses a default black background. Set it to white when
889 * 'background' is "light". */
890 if (*p_bg == 'l')
891 {
892 VTermColor fg, bg;
893
894 fg.red = fg.green = fg.blue = 0;
895 bg.red = bg.green = bg.blue = 255;
896 vterm_state_set_default_colors(vterm_obtain_state(vterm), &fg, &bg);
897 }
898
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +0200899 /* Required to initialize most things. */
900 vterm_screen_reset(screen, 1 /* hard */);
901}
902
903# ifdef WIN3264
904
905#define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
906#define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
907
908void* (*winpty_config_new)(int, void*);
909void* (*winpty_open)(void*, void*);
910void* (*winpty_spawn_config_new)(int, void*, LPCWSTR, void*, void*, void*);
911BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
912void (*winpty_config_set_initial_size)(void*, int, int);
913LPCWSTR (*winpty_conin_name)(void*);
914LPCWSTR (*winpty_conout_name)(void*);
915LPCWSTR (*winpty_conerr_name)(void*);
916void (*winpty_free)(void*);
917void (*winpty_config_free)(void*);
918void (*winpty_spawn_config_free)(void*);
919void (*winpty_error_free)(void*);
920LPCWSTR (*winpty_error_msg)(void*);
921
922/**************************************
923 * 2. MS-Windows implementation.
924 */
925
926#define WINPTY_DLL "winpty.dll"
927
928static HINSTANCE hWinPtyDLL = NULL;
929
930 int
931dyn_winpty_init(void)
932{
933 int i;
934 static struct
935 {
936 char *name;
937 FARPROC *ptr;
938 } winpty_entry[] =
939 {
940 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
941 {"winpty_config_free", (FARPROC*)&winpty_config_free},
942 {"winpty_config_new", (FARPROC*)&winpty_config_new},
943 {"winpty_config_set_initial_size", (FARPROC*)&winpty_config_set_initial_size},
944 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
945 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
946 {"winpty_error_free", (FARPROC*)&winpty_error_free},
947 {"winpty_free", (FARPROC*)&winpty_free},
948 {"winpty_open", (FARPROC*)&winpty_open},
949 {"winpty_spawn", (FARPROC*)&winpty_spawn},
950 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
951 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
952 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
953 {NULL, NULL}
954 };
955
956 /* No need to initialize twice. */
957 if (hWinPtyDLL)
958 return 1;
959 /* Load winpty.dll */
960 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
961 if (!hWinPtyDLL)
962 {
963 EMSG2(_(e_loadlib), WINPTY_DLL);
964 return 0;
965 }
966 for (i = 0; winpty_entry[i].name != NULL
967 && winpty_entry[i].ptr != NULL; ++i)
968 {
969 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
970 winpty_entry[i].name)) == NULL)
971 {
972 EMSG2(_(e_loadfunc), winpty_entry[i].name);
973 return 0;
974 }
975 }
976
977 return 1;
978}
979
980/*
981 * Create a new terminal of "rows" by "cols" cells.
982 * Store a reference in "term".
983 * Return OK or FAIL.
984 */
985 static int
986term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
987{
988 WCHAR *p = enc_to_utf16(cmd, NULL);
989 channel_T *channel = NULL;
990 job_T *job = NULL;
991 jobopt_T opt;
992 DWORD error;
993 HANDLE jo = NULL, child_process_handle, child_thread_handle;
994 void *winpty_err;
995 void *spawn_config;
996
997 if (!dyn_winpty_init())
998 return FAIL;
999
1000 if (p == NULL)
1001 return FAIL;
1002
1003 job = job_alloc();
1004 if (job == NULL)
1005 goto failed;
1006
1007 channel = add_channel();
1008 if (channel == NULL)
1009 goto failed;
1010
1011 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
1012 if (term->tl_winpty_config == NULL)
1013 goto failed;
1014
1015 winpty_config_set_initial_size(term->tl_winpty_config, cols, rows);
1016 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
1017 if (term->tl_winpty == NULL)
1018 goto failed;
1019
1020 spawn_config = winpty_spawn_config_new(
1021 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
1022 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
1023 NULL,
1024 p,
1025 NULL,
1026 NULL,
1027 &winpty_err);
1028 if (spawn_config == NULL)
1029 goto failed;
1030
1031 channel = add_channel();
1032 if (channel == NULL)
1033 goto failed;
1034
1035 job = job_alloc();
1036 if (job == NULL)
1037 goto failed;
1038
1039 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
1040 &child_thread_handle, &error, &winpty_err))
1041 goto failed;
1042
1043 channel_set_pipes(channel,
1044 (sock_T) CreateFileW(
1045 winpty_conin_name(term->tl_winpty),
1046 GENERIC_WRITE, 0, NULL,
1047 OPEN_EXISTING, 0, NULL),
1048 (sock_T) CreateFileW(
1049 winpty_conout_name(term->tl_winpty),
1050 GENERIC_READ, 0, NULL,
1051 OPEN_EXISTING, 0, NULL),
1052 (sock_T) CreateFileW(
1053 winpty_conerr_name(term->tl_winpty),
1054 GENERIC_READ, 0, NULL,
1055 OPEN_EXISTING, 0, NULL));
1056
1057 jo = CreateJobObject(NULL, NULL);
1058 if (jo == NULL)
1059 goto failed;
1060
1061 if (!AssignProcessToJobObject(jo, child_process_handle))
1062 goto failed;
1063
1064 winpty_spawn_config_free(spawn_config);
1065
1066 create_vterm(term, rows, cols);
1067
1068 setup_job_options(&opt, rows, cols);
1069 channel_set_job(channel, job, &opt);
1070
1071 job->jv_channel = channel;
1072 job->jv_proc_info.hProcess = child_process_handle;
1073 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
1074 job->jv_job_object = jo;
1075 job->jv_status = JOB_STARTED;
1076 term->tl_job = job;
1077
1078 return OK;
1079
1080failed:
1081 if (channel != NULL)
1082 channel_clear(channel);
1083 if (job != NULL)
1084 job_cleanup(job);
1085 if (jo != NULL)
1086 CloseHandle(jo);
1087 if (term->tl_winpty != NULL)
1088 winpty_free(term->tl_winpty);
1089 if (term->tl_winpty_config != NULL)
1090 winpty_config_free(term->tl_winpty_config);
1091 if (winpty_err != NULL)
1092 {
1093 char_u *msg = utf16_to_enc(
1094 (short_u *)winpty_error_msg(winpty_err), NULL);
1095
1096 EMSG(msg);
1097 winpty_error_free(winpty_err);
1098 }
1099 return FAIL;
1100}
1101
1102/*
1103 * Free the terminal emulator part of "term".
1104 */
1105 static void
1106term_free(term_T *term)
1107{
1108 winpty_free(term->tl_winpty);
1109 winpty_config_free(term->tl_winpty_config);
1110 vterm_free(term->tl_vterm);
1111}
1112
1113# else
1114
1115/**************************************
1116 * 3. Unix-like implementation.
1117 */
1118
1119/*
1120 * Create a new terminal of "rows" by "cols" cells.
1121 * Start job for "cmd".
1122 * Store the pointers in "term".
1123 * Return OK or FAIL.
1124 */
1125 static int
1126term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
1127{
1128 typval_T argvars[2];
1129 jobopt_T opt;
1130
1131 create_vterm(term, rows, cols);
1132
1133 argvars[0].v_type = VAR_STRING;
1134 argvars[0].vval.v_string = cmd;
1135 setup_job_options(&opt, rows, cols);
1136 term->tl_job = job_start(argvars, &opt);
1137
Bram Moolenaar61a66052017-07-22 18:39:00 +02001138 return term->tl_job != NULL
1139 && term->tl_job->jv_channel != NULL
1140 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
Bram Moolenaar8f84c3a2017-07-22 16:14:44 +02001141}
1142
1143/*
1144 * Free the terminal emulator part of "term".
1145 */
1146 static void
1147term_free(term_T *term)
1148{
1149 vterm_free(term->tl_vterm);
1150}
1151# endif
Bram Moolenaar8c0095c2017-07-18 22:53:21 +02001152
Bram Moolenaare4f25e42017-07-07 11:54:15 +02001153#endif /* FEAT_TERMINAL */