comparison src/terminal.c @ 11757:74abb6c84984 v8.0.0761

patch 8.0.0761: options not set properly for a terminal buffer commit https://github.com/vim/vim/commit/1f2903c43109b16594d141a730659317b15f388d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 23 19:51:01 2017 +0200 patch 8.0.0761: options not set properly for a terminal buffer Problem: Options of a buffer for a terminal window are not set properly. Solution: Add "terminal" value for 'buftype'. Make 'buftype' and 'bufhidden' not depend on the quickfix feature. Also set the buffer name and show "running" or "finished" in the window title.
author Christian Brabandt <cb@256bit.org>
date Sun, 23 Jul 2017 20:00:05 +0200
parents 12fa6072977a
children b82dad3fa176
comparison
equal deleted inserted replaced
11756:e3e89d6460d0 11757:74abb6c84984
31 * terminal emulator invokes callbacks when its screen content changes. 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 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. 33 * while, if the terminal window is visible, the screen contents is drawn.
34 * 34 *
35 * TODO: 35 * TODO:
36 * - cursor flickers when moving the cursor 36 * - do not store terminal buffer in viminfo
37 * - set buffer options to be scratch, hidden, nomodifiable, etc. 37 * - put terminal title in the statusline
38 * - set buffer name to command, add (1) to avoid duplicates.
39 * - Add a scrollback buffer (contains lines to scroll off the top). 38 * - Add a scrollback buffer (contains lines to scroll off the top).
40 * Can use the buf_T lines, store attributes somewhere else? 39 * Can use the buf_T lines, store attributes somewhere else?
41 * - When the job ends: 40 * - When the job ends:
42 * - Write "-- JOB ENDED --" in the terminal. 41 * - Write "-- JOB ENDED --" in the terminal.
43 * - Put the terminal contents in the scrollback buffer. 42 * - Put the terminal contents in the scrollback buffer.
51 * - add test for giving error for invalid 'termsize' value. 50 * - add test for giving error for invalid 'termsize' value.
52 * - support minimal size when 'termsize' is "rows*cols". 51 * - support minimal size when 'termsize' is "rows*cols".
53 * - support minimal size when 'termsize' is empty? 52 * - support minimal size when 'termsize' is empty?
54 * - implement "term" for job_start(): more job options when starting a 53 * - implement "term" for job_start(): more job options when starting a
55 * terminal. 54 * terminal.
56 * - implement ":buf {term-buf-name}"
57 * - implement term_list() list of buffers with a terminal 55 * - implement term_list() list of buffers with a terminal
58 * - implement term_getsize(buf) 56 * - implement term_getsize(buf)
59 * - implement term_setsize(buf) 57 * - implement term_setsize(buf)
60 * - implement term_sendkeys(buf, keys) send keystrokes to a terminal 58 * - implement term_sendkeys(buf, keys) send keystrokes to a terminal
61 * - implement term_wait(buf) wait for screen to be updated 59 * - implement term_wait(buf) wait for screen to be updated
190 188
191 /* Link the new terminal in the list of active terminals. */ 189 /* Link the new terminal in the list of active terminals. */
192 term->tl_next = first_term; 190 term->tl_next = first_term;
193 first_term = term; 191 first_term = term;
194 192
195 /* TODO: set buffer type, hidden, etc. */ 193 if (buflist_findname(cmd) == NULL)
194 curbuf->b_ffname = vim_strsave(cmd);
195 else
196 {
197 int i;
198 size_t len = STRLEN(cmd) + 10;
199 char_u *p = alloc(len);
200
201 for (i = 1; p != NULL; ++i)
202 {
203 vim_snprintf((char *)p, len, "%s (%d)", cmd, i);
204 if (buflist_findname(p) == NULL)
205 {
206 curbuf->b_ffname = p;
207 break;
208 }
209 }
210 }
211 curbuf->b_fname = curbuf->b_ffname;
212
213 /* Mark the buffer as changed, so that it's not easy to abandon the job. */
214 curbuf->b_changed = TRUE;
215 curbuf->b_p_ma = FALSE;
216 set_string_option_direct((char_u *)"buftype", -1,
217 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
196 218
197 set_term_and_win_size(term); 219 set_term_and_win_size(term);
198 220
199 if (cmd == NULL || *cmd == NUL) 221 if (cmd == NULL || *cmd == NUL)
200 cmd = p_sh; 222 cmd = p_sh;
488 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, 510 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
489 (char_u *)buf, len, NULL); 511 (char_u *)buf, len, NULL);
490 } 512 }
491 } 513 }
492 514
515 /*
516 * Called when a job has finished.
517 */
518 void
519 term_job_ended(job_T *job)
520 {
521 if (curbuf->b_term != NULL && curbuf->b_term->tl_job == job)
522 maketitle();
523 }
524
525 /*
526 * Return TRUE if the job for "buf" is still running.
527 */
528 int
529 term_job_running(buf_T *buf)
530 {
531 return buf->b_term != NULL && buf->b_term->tl_job != NULL
532 && buf->b_term->tl_job->jv_status == JOB_STARTED;
533 }
534
493 static void 535 static void
494 position_cursor(win_T *wp, VTermPos *pos) 536 position_cursor(win_T *wp, VTermPos *pos)
495 { 537 {
496 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); 538 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
497 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1)); 539 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
848 clear_job_options(opt); 890 clear_job_options(opt);
849 opt->jo_mode = MODE_RAW; 891 opt->jo_mode = MODE_RAW;
850 opt->jo_out_mode = MODE_RAW; 892 opt->jo_out_mode = MODE_RAW;
851 opt->jo_err_mode = MODE_RAW; 893 opt->jo_err_mode = MODE_RAW;
852 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; 894 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
895
853 opt->jo_io[PART_OUT] = JIO_BUFFER; 896 opt->jo_io[PART_OUT] = JIO_BUFFER;
854 opt->jo_io[PART_ERR] = JIO_BUFFER; 897 opt->jo_io[PART_ERR] = JIO_BUFFER;
855 opt->jo_set |= JO_OUT_IO + (JO_OUT_IO << (PART_ERR - PART_OUT)); 898 opt->jo_set |= JO_OUT_IO + JO_ERR_IO;
899
900 opt->jo_modifiable[PART_OUT] = 0;
901 opt->jo_modifiable[PART_ERR] = 0;
902 opt->jo_set |= JO_OUT_MODIFIABLE + JO_ERR_MODIFIABLE;
903
856 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; 904 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
857 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; 905 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
858 opt->jo_pty = TRUE; 906 opt->jo_pty = TRUE;
859 opt->jo_set |= JO_OUT_BUF + (JO_OUT_BUF << (PART_ERR - PART_OUT)); 907 opt->jo_set |= JO_OUT_BUF + JO_ERR_BUF;
908
860 opt->jo_term_rows = rows; 909 opt->jo_term_rows = rows;
861 opt->jo_term_cols = cols; 910 opt->jo_term_cols = cols;
862 } 911 }
863 912
864 /* 913 /*