comparison src/terminal.c @ 12313:44f3c9b7eec4 v8.0.1036

patch 8.0.1036: ++eof argument for terminal only available on MS-Windows commit https://github.com/vim/vim/commit/dada6d2a8e887309e88cb126f1251d81f91b4b9d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 2 17:18:35 2017 +0200 patch 8.0.1036: ++eof argument for terminal only available on MS-Windows Problem: ++eof argument for terminal only available on MS-Windows. Solution: Also support ++eof on Unix. Add a test.
author Christian Brabandt <cb@256bit.org>
date Sat, 02 Sep 2017 17:30:03 +0200
parents 66fa8eabbd6e
children 2a8890b80923
comparison
equal deleted inserted replaced
12312:754e3ee717e3 12313:44f3c9b7eec4
108 108
109 int tl_normal_mode; /* TRUE: Terminal-Normal mode */ 109 int tl_normal_mode; /* TRUE: Terminal-Normal mode */
110 int tl_channel_closed; 110 int tl_channel_closed;
111 int tl_finish; /* 'c' for ++close, 'o' for ++open */ 111 int tl_finish; /* 'c' for ++close, 'o' for ++open */
112 char_u *tl_opencmd; 112 char_u *tl_opencmd;
113 char_u *tl_eof_chars;
113 114
114 #ifdef WIN3264 115 #ifdef WIN3264
115 void *tl_winpty_config; 116 void *tl_winpty_config;
116 void *tl_winpty; 117 void *tl_winpty;
117 char_u *tl_eof_chars;
118 #endif 118 #endif
119 119
120 /* last known vterm size */ 120 /* last known vterm size */
121 int tl_rows; 121 int tl_rows;
122 int tl_cols; 122 int tl_cols;
388 curbuf->b_fname = curbuf->b_ffname; 388 curbuf->b_fname = curbuf->b_ffname;
389 389
390 if (opt->jo_term_opencmd != NULL) 390 if (opt->jo_term_opencmd != NULL)
391 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); 391 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
392 392
393 # ifdef WIN3264
394 if (opt->jo_eof_chars != NULL) 393 if (opt->jo_eof_chars != NULL)
395 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); 394 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
396 # endif
397 395
398 set_string_option_direct((char_u *)"buftype", -1, 396 set_string_option_direct((char_u *)"buftype", -1,
399 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0); 397 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
400 398
401 /* Mark the buffer as not modifiable. It can only be made modifiable after 399 /* Mark the buffer as not modifiable. It can only be made modifiable after
497 p = skiptowhite(cmd); 495 p = skiptowhite(cmd);
498 } 496 }
499 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0 497 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
500 && ep != NULL) 498 && ep != NULL)
501 { 499 {
502 # ifdef WIN3264
503 char_u *buf = NULL; 500 char_u *buf = NULL;
504 char_u *keys; 501 char_u *keys;
505 502
506 p = skiptowhite(cmd); 503 p = skiptowhite(cmd);
507 *p = NUL; 504 *p = NUL;
508 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE); 505 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE);
509 opt.jo_set2 |= JO2_EOF_CHARS; 506 opt.jo_set2 |= JO2_EOF_CHARS;
510 opt.jo_eof_chars = vim_strsave(keys); 507 opt.jo_eof_chars = vim_strsave(keys);
511 vim_free(buf); 508 vim_free(buf);
512 *p = ' '; 509 *p = ' ';
513 # else
514 p = skiptowhite(cmd);
515 # endif
516 } 510 }
517 else 511 else
518 { 512 {
519 if (*p) 513 if (*p)
520 *p = NUL; 514 *p = NUL;
592 586
593 term_free_vterm(term); 587 term_free_vterm(term);
594 vim_free(term->tl_title); 588 vim_free(term->tl_title);
595 vim_free(term->tl_status_text); 589 vim_free(term->tl_status_text);
596 vim_free(term->tl_opencmd); 590 vim_free(term->tl_opencmd);
597 # ifdef WIN3264
598 vim_free(term->tl_eof_chars); 591 vim_free(term->tl_eof_chars);
599 # endif
600 vim_free(term->tl_cursor_color); 592 vim_free(term->tl_cursor_color);
601 vim_free(term); 593 vim_free(term);
602 buf->b_term = NULL; 594 buf->b_term = NULL;
603 if (in_terminal_loop == term) 595 if (in_terminal_loop == term)
604 in_terminal_loop = NULL; 596 in_terminal_loop = NULL;
2915 * TODO: is there a better way? */ 2907 * TODO: is there a better way? */
2916 parse_queued_messages(); 2908 parse_queued_messages();
2917 } 2909 }
2918 } 2910 }
2919 2911
2912 /*
2913 * Called when a channel has sent all the lines to a terminal.
2914 * Send a CTRL-D to mark the end of the text.
2915 */
2916 void
2917 term_send_eof(channel_T *ch)
2918 {
2919 term_T *term;
2920
2921 for (term = first_term; term != NULL; term = term->tl_next)
2922 if (term->tl_job == ch->ch_job)
2923 {
2924 if (term->tl_eof_chars != NULL)
2925 {
2926 channel_send(ch, PART_IN, term->tl_eof_chars,
2927 (int)STRLEN(term->tl_eof_chars), NULL);
2928 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
2929 }
2930 # ifdef WIN3264
2931 else
2932 /* Default: CTRL-D */
2933 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
2934 # endif
2935 }
2936 }
2937
2920 # if defined(WIN3264) || defined(PROTO) 2938 # if defined(WIN3264) || defined(PROTO)
2921 2939
2922 /************************************** 2940 /**************************************
2923 * 2. MS-Windows implementation. 2941 * 2. MS-Windows implementation.
2924 */ 2942 */
3214 terminal_enabled(void) 3232 terminal_enabled(void)
3215 { 3233 {
3216 return dyn_winpty_init(FALSE) == OK; 3234 return dyn_winpty_init(FALSE) == OK;
3217 } 3235 }
3218 3236
3219 /*
3220 * Called when a channel has sent all the lines to a terminal.
3221 * Send a CTRL-D to mark the end of the text.
3222 */
3223 void
3224 term_send_eof(channel_T *ch)
3225 {
3226 term_T *term;
3227
3228 for (term = first_term; term != NULL; term = term->tl_next)
3229 if (term->tl_job == ch->ch_job)
3230 {
3231 if (term->tl_eof_chars != NULL)
3232 channel_send(ch, PART_IN, term->tl_eof_chars,
3233 (int)STRLEN(term->tl_eof_chars), NULL);
3234 else
3235 /* Default: CTRL-D */
3236 channel_send(ch, PART_IN, (char_u *)"\004", 1, NULL);
3237 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
3238 }
3239 }
3240
3241 # else 3237 # else
3242 3238
3243 /************************************** 3239 /**************************************
3244 * 3. Unix-like implementation. 3240 * 3. Unix-like implementation.
3245 */ 3241 */