comparison src/terminal.c @ 11690:ce434212d682 v8.0.0728

patch 8.0.0728: the terminal structure is never freed commit https://github.com/vim/vim/commit/96ca27a0ee8ae738cab9fb386984c75c6821e31a Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 17 23:20:24 2017 +0200 patch 8.0.0728: the terminal structure is never freed Problem: The terminal structure is never freed. Solution: Free the structure and unreference what it contains.
author Christian Brabandt <cb@256bit.org>
date Mon, 17 Jul 2017 23:30:03 +0200
parents 1ce1376fbbf8
children 8f5840a59b31
comparison
equal deleted inserted replaced
11689:d0213284cfb4 11690:ce434212d682
23 * If the job produces output, it is written to the VTerm. 23 * If the job produces output, it is written to the VTerm.
24 * This will result in screen updates. 24 * This will result in screen updates.
25 * 25 *
26 * TODO: 26 * TODO:
27 * - pressing Enter sends two CR and/or NL characters to "bash -i"? 27 * - pressing Enter sends two CR and/or NL characters to "bash -i"?
28 * - free b_term when closing terminal. 28 * Passing Enter as NL seems to work.
29 * - remove term from first_term list when closing terminal.
30 * - set buffer options to be scratch, hidden, nomodifiable, etc. 29 * - set buffer options to be scratch, hidden, nomodifiable, etc.
31 * - set buffer name to command, add (1) to avoid duplicates. 30 * - set buffer name to command, add (1) to avoid duplicates.
32 * - if buffer is wiped, cleanup terminal, may stop job. 31 * - If [command] is not given the 'shell' option is used.
33 * - if the job ends, write "-- JOB ENDED --" in the terminal 32 * - if the job ends, write "-- JOB ENDED --" in the terminal
34 * - when closing window and job ended, delete the terminal 33 * - when closing window and job ended, delete the terminal
35 * - when closing window and job has not ended, make terminal hidden? 34 * - when closing window and job has not ended, make terminal hidden?
36 * - Use a pty for I/O with the job. 35 * - Use a pty for I/O with the job.
37 * - Windows implementation: 36 * - Windows implementation:
41 * - command line completion for :terminal 40 * - command line completion for :terminal
42 * - support fixed size when 'termsize' is "rowsXcols". 41 * - support fixed size when 'termsize' is "rowsXcols".
43 * - support minimal size when 'termsize' is "rows*cols". 42 * - support minimal size when 'termsize' is "rows*cols".
44 * - support minimal size when 'termsize' is empty. 43 * - support minimal size when 'termsize' is empty.
45 * - implement ":buf {term-buf-name}" 44 * - implement ":buf {term-buf-name}"
46 * - implement term_getsize() 45 * - implement term_list() list of buffers with a terminal
47 * - implement term_setsize() 46 * - implement term_getsize(buf)
48 * - implement term_sendkeys() send keystrokes to a terminal 47 * - implement term_setsize(buf)
49 * - implement term_wait() wait for screen to be updated 48 * - implement term_sendkeys(buf, keys) send keystrokes to a terminal
50 * - implement term_scrape() inspect terminal screen 49 * - implement term_wait(buf) wait for screen to be updated
51 * - implement term_open() open terminal window 50 * - implement term_scrape(buf, row) inspect terminal screen
52 * - implement term_getjob() 51 * - implement term_open(command, options) open terminal window
52 * - implement term_getjob(buf)
53 * - implement 'termkey' 53 * - implement 'termkey'
54 */ 54 */
55 55
56 #include "vim.h" 56 #include "vim.h"
57 57
163 vterm_set_utf8(vterm, 1); 163 vterm_set_utf8(vterm, 1);
164 /* Required to initialize most things. */ 164 /* Required to initialize most things. */
165 vterm_screen_reset(screen, 1 /* hard */); 165 vterm_screen_reset(screen, 1 /* hard */);
166 166
167 /* By default NL means CR-NL. */ 167 /* By default NL means CR-NL. */
168 /* TODO: this causes two prompts when using ":term bash -i". */
169 vterm_input_write(vterm, "\x1b[20h", 5); 168 vterm_input_write(vterm, "\x1b[20h", 5);
170 169
171 argvars[0].v_type = VAR_STRING; 170 argvars[0].v_type = VAR_STRING;
172 argvars[0].vval.v_string = eap->arg; 171 argvars[0].vval.v_string = eap->arg;
173 172
183 opt.jo_io_buf[PART_ERR] = curbuf->b_fnum; 182 opt.jo_io_buf[PART_ERR] = curbuf->b_fnum;
184 opt.jo_set |= JO_OUT_BUF + (JO_OUT_BUF << (PART_ERR - PART_OUT)); 183 opt.jo_set |= JO_OUT_BUF + (JO_OUT_BUF << (PART_ERR - PART_OUT));
185 184
186 term->tl_job = job_start(argvars, &opt); 185 term->tl_job = job_start(argvars, &opt);
187 186
188 /* TODO: setup channel to job */ 187 if (term->tl_job == NULL)
188 /* Wiping out the buffer will also close the window. */
189 do_buffer(DOBUF_WIPE, DOBUF_CURRENT, FORWARD, 0, TRUE);
190
189 /* Setup pty, see mch_call_shell(). */ 191 /* Setup pty, see mch_call_shell(). */
192 }
193
194 /*
195 * Free a terminal and everything it refers to.
196 * Kills the job if there is one.
197 * Called when wiping out a buffer.
198 */
199 void
200 free_terminal(term_T *term)
201 {
202 term_T *tp;
203
204 if (term == NULL)
205 return;
206 if (first_term == term)
207 first_term = term->tl_next;
208 else
209 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
210 if (tp->tl_next == term)
211 {
212 tp->tl_next = term->tl_next;
213 break;
214 }
215
216 if (term->tl_job != NULL)
217 {
218 if (term->tl_job->jv_status != JOB_ENDED)
219 job_stop(term->tl_job, NULL, "kill");
220 job_unref(term->tl_job);
221 }
222
223 vterm_free(term->tl_vterm);
224 vim_free(term);
190 } 225 }
191 226
192 /* 227 /*
193 * Invoked when "msg" output from a job was received. Write it to the terminal 228 * Invoked when "msg" output from a job was received. Write it to the terminal
194 * of "buffer". 229 * of "buffer".
338 { 373 {
339 case Ctrl_W: 374 case Ctrl_W:
340 stuffcharReadbuff(Ctrl_W); 375 stuffcharReadbuff(Ctrl_W);
341 return; 376 return;
342 377
378 /* TODO: which of these two should be used? */
379 #if 0
343 case CAR: key = VTERM_KEY_ENTER; break; 380 case CAR: key = VTERM_KEY_ENTER; break;
381 #else
382 case CAR: c = NL; break;
383 #endif
344 case ESC: key = VTERM_KEY_ESCAPE; break; 384 case ESC: key = VTERM_KEY_ESCAPE; break;
345 case K_BS: key = VTERM_KEY_BACKSPACE; break; 385 case K_BS: key = VTERM_KEY_BACKSPACE; break;
346 case K_DEL: key = VTERM_KEY_DEL; break; 386 case K_DEL: key = VTERM_KEY_DEL; break;
347 case K_DOWN: key = VTERM_KEY_DOWN; break; 387 case K_DOWN: key = VTERM_KEY_DOWN; break;
348 case K_END: key = VTERM_KEY_END; break; 388 case K_END: key = VTERM_KEY_END; break;