changeset 15746:c017195b121b v8.1.0880

patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty commit https://github.com/vim/vim/commit/c6ddce3f2cf6daa3a545405373b661f8a9bccad9 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 8 12:47:03 2019 +0100 patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty Problem: MS-Windows: inconsistent selection of winpty/conpty. Solution: Name option 'termwintype', use ++type argument and "term_pty" for term_start(). (Hirohito Higashi, closes #3915)
author Bram Moolenaar <Bram@vim.org>
date Fri, 08 Feb 2019 13:00:08 +0100
parents 655ee4b0a5cc
children ac3d51cbfc83
files runtime/doc/eval.txt runtime/doc/options.txt runtime/doc/quickref.txt runtime/doc/terminal.txt runtime/optwin.vim src/channel.c src/option.c src/option.h src/structs.h src/terminal.c src/testdir/gen_opt_test.vim src/version.c
diffstat 12 files changed, 108 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -5750,6 +5750,11 @@ job_info([{job}])					*job_info()*
 				(See |job_stop()| for the values)
 				only valid when "status" is "dead"
 
+		   Only in MS-Windows:
+		   "tty_type"	Type of virtual console in use.
+				Values are "winpty" or "conpty".
+				See 'termwintype'.
+
 		Without any arguments, returns a List with all Job objects.
 
 job_setoptions({job}, {options})			*job_setoptions()*
@@ -9469,10 +9474,8 @@ term_start({cmd}, {options})				*term_st
 		   "ansi_colors"     A list of 16 color names or hex codes
 				     defining the ANSI palette used in GUI
 				     color modes.  See |g:terminal_ansi_colors|.
-		   "term_mode"	     (MS-Windows only): Specify which pty to
-				     use:
-					"winpty": Use winpty
-					"conpty": Use ConPTY (if available)
+		   "tty_type"	     (MS-Windows only): Specify which pty to
+				     use.  See 'termwintype' for the values.
 
 		{only available when compiled with the |+terminal| feature}
 
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -8054,23 +8054,6 @@ A jump table for the options with a shor
 	Note that the "cterm" attributes are still used, not the "gui" ones.
 	NOTE: This option is reset when 'compatible' is set.
 
-						*'termmode'* *'tmod'*
-'termmode' 'tmod'	string  (default "")
-			local to window
-			{not in Vi, MS-Windows only}
-	Whether the window uses winpty or |ConPTY| as the virtual console.
-	When set before opening the terminal, it influences what pty is used.
-	When opening the terminal it will be set to the actually used pty.
-
-	Possible values are:
-	    ""		use ConPTY if possible, winpty otherwise
-	    "winpty"	use winpty, fail if not supported
-	    "conpty"	use |ConPTY|, fail if not supported
-
-	|ConPTY| support depends on the platform (Windows 10 October 2018
-	edition).  winpty support needs to be installed.  If neither is
-	supported then you cannot open a terminal window.
-
 						*'termwinscroll'* *'twsl'*
 'termwinscroll' 'twsl'	number	(default 10000)
 			local to buffer
@@ -8119,6 +8102,24 @@ A jump table for the options with a shor
 	the size of the terminal.  In that case the Vim window will be
 	adjusted to that size, if possible.
 
+						*'termwintype'* *'twt'*
+'termwintype' 'twt'	string  (default "")
+			global
+			{not in Vi}
+			{only available when compiled with the |terminal|
+			feature on MS-Windows}
+	Specify the virtual console (pty) used when opening the terminal
+	window.
+
+	Possible values are:
+	    ""		use ConPTY if possible, winpty otherwise
+	    "winpty"	use winpty, fail if not supported
+	    "conpty"	use |ConPTY|, fail if not supported
+
+	|ConPTY| support depends on the platform (Windows 10 October 2018
+	edition).  winpty support needs to be installed.  If neither is
+	supported then you cannot open a terminal window.
+
 						*'terse'* *'noterse'*
 'terse'			boolean	(default off)
 			global
--- a/runtime/doc/quickref.txt
+++ b/runtime/doc/quickref.txt
@@ -1,4 +1,4 @@
-*quickref.txt*  For Vim version 8.1.  Last change: 2018 Apr 18
+*quickref.txt*  For Vim version 8.1.  Last change: 2019 Feb 08
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -930,6 +930,7 @@ Short explanation of each option:		*opti
 'termwinkey'	  'twk'	    key that precedes a Vim command in a terminal
 'termwinscroll'   'twsl'    max number of scrollback lines in a terminal window
 'termwinsize'	  'tws'	    size of a terminal window
+'termwintype'	  'twt'	    MS-Windows: type of pty to use for terminal window
 'terse'			    shorten some messages
 'textauto'	  'ta'	    obsolete, use 'fileformats'
 'textmode'	  'tx'	    obsolete, use 'fileformat'
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -228,8 +228,10 @@ Syntax ~
 					for Python "++eof=exit()".  Special
 					codes can be used like with `:map`,
 					e.g. "<C-Z>" for CTRL-Z.
-			++winpty	Use winpty as the virtual console.
-			++conpty	Use |ConPTY| as the virtual console.
+			++type={pty}	(MS-Windows only): Use {pty} as the
+					virtual console.  See 'termwintype'
+					for the values.
+
 			If you want to use more options use the |term_start()|
 			function.
 			If you want to split the window vertically, use: >
@@ -416,8 +418,8 @@ On more recent versions of MS-Windows 10
 Update"), winpty is no longer required. On those versions, |:terminal| will use
 Windows' built-in support for hosting terminal applications, "ConPTY".  When
 ConPTY is in use, there may be rendering artifacts regarding ambiguous-width
-characters. If you encounter any such issues, set 'termmode' to winpty (which
-you then must have instlled).
+characters. If you encounter any such issues, set 'termwintype' to "winpty"
+(which you then must have instlled).
 
 Environment variables are used to pass information to the running job:
     VIM_SERVERNAME	v:servername
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
@@ -1,7 +1,7 @@
 " These commands create the option window.
 "
 " Maintainer:	Bram Moolenaar <Bram@vim.org>
-" Last Change:	2019 Jan 27
+" Last Change:	2019 Feb 08
 
 " If there already is an option window, jump to that one.
 let buf = bufnr('option-window')
@@ -503,6 +503,10 @@ if has("terminal")
   call <SID>OptionL("twk")
   call append("$", "termwinscroll\tmax number of lines to keep for scrollback in a terminal window")
   call append("$", "\t(local to window)")
+  if has('win32')
+    call append("$", "termwintype\ttype of pty to use for a terminal window")
+    call <SID>OptionG("twt", &twt)
+  endif
   call <SID>OptionL("twsl")
   if exists("&winptydll")
     call append("$", "winptydll\tname of the winpty dynamic library")
--- a/src/channel.c
+++ b/src/channel.c
@@ -4947,27 +4947,27 @@ get_job_options(typval_T *tv, jobopt_T *
 		opt->jo_set2 |= JO2_TERM_KILL;
 		opt->jo_term_kill = tv_get_string_chk(item);
 	    }
-	    else if (STRCMP(hi->hi_key, "term_mode") == 0)
+	    else if (STRCMP(hi->hi_key, "tty_type") == 0)
 	    {
 		char_u *p;
 
-		if (!(supported2 & JO2_TERM_MODE))
+		if (!(supported2 & JO2_TTY_TYPE))
 		    break;
-		opt->jo_set2 |= JO2_TERM_MODE;
+		opt->jo_set2 |= JO2_TTY_TYPE;
 		p = tv_get_string_chk(item);
 		if (p == NULL)
 		{
-		    semsg(_(e_invargval), "term_mode");
+		    semsg(_(e_invargval), "tty_type");
 		    return FAIL;
 		}
 		// Allow empty string, "winpty", "conpty".
 		if (!(*p == NUL || STRCMP(p, "winpty") == 0
 					          || STRCMP(p, "conpty") == 0))
 		{
-		    semsg(_(e_invargval), "term_mode");
+		    semsg(_(e_invargval), "tty_type");
 		    return FAIL;
 		}
-		opt->jo_term_mode = p[0];
+		opt->jo_tty_type = p[0];
 	    }
 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
 	    else if (STRCMP(hi->hi_key, "ansi_colors") == 0)
@@ -5194,6 +5194,9 @@ job_free_contents(job_T *job)
 #ifdef UNIX
     vim_free(job->jv_termsig);
 #endif
+#ifdef WIN3264
+    vim_free(job->jv_tty_type);
+#endif
     free_callback(job->jv_exit_cb, job->jv_exit_partial);
     if (job->jv_argv != NULL)
     {
@@ -5963,6 +5966,9 @@ job_info(job_T *job, dict_T *dict)
 #ifdef UNIX
     dict_add_string(dict, "termsig", job->jv_termsig);
 #endif
+#ifdef WIN3264
+    dict_add_string(dict, "tty_type", job->jv_tty_type);
+#endif
 
     l = list_alloc();
     if (l != NULL)
--- a/src/option.c
+++ b/src/option.c
@@ -253,7 +253,6 @@
 # define PV_TWK		OPT_WIN(WV_TWK)
 # define PV_TWS		OPT_WIN(WV_TWS)
 # define PV_TWSL	OPT_BUF(BV_TWSL)
-# define PV_TMOD	OPT_WIN(WV_TMOD)
 #endif
 #ifdef FEAT_SIGNS
 # define PV_SCL		OPT_WIN(WV_SCL)
@@ -2701,15 +2700,6 @@ static struct vimoption options[] =
 			    {(char_u *)FALSE, (char_u *)FALSE}
 #endif
 			    SCTX_INIT},
-    {"termmode", "tmod",    P_STRING|P_ALLOCED|P_VI_DEF,
-#ifdef FEAT_TERMINAL
-			    (char_u *)VAR_WIN, PV_TMOD,
-			    {(char_u *)"", (char_u *)NULL}
-#else
-			    (char_u *)NULL, PV_NONE,
-			    {(char_u *)NULL, (char_u *)0L}
-#endif
-			    SCTX_INIT},
     {"termwinkey", "twk",   P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
 #ifdef FEAT_TERMINAL
 			    (char_u *)VAR_WIN, PV_TWK,
@@ -2737,6 +2727,15 @@ static struct vimoption options[] =
 			    {(char_u *)NULL, (char_u *)0L}
 #endif
 			    SCTX_INIT},
+    {"termwintype", "twt",  P_STRING|P_ALLOCED|P_VI_DEF,
+#if defined(WIN3264) && defined(FEAT_TERMINAL)
+			    (char_u *)&p_twt, PV_NONE,
+			    {(char_u *)"", (char_u *)NULL}
+#else
+			    (char_u *)NULL, PV_NONE,
+			    {(char_u *)NULL, (char_u *)0L}
+#endif
+			    SCTX_INIT},
     {"terse",	    NULL,   P_BOOL|P_VI_DEF,
 			    (char_u *)&p_terse, PV_NONE,
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
@@ -3218,8 +3217,8 @@ static char *(p_cot_values[]) = {"menu",
 #ifdef FEAT_SIGNS
 static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
 #endif
-#ifdef FEAT_TERMINAL
-static char *(p_tmod_values[]) = {"winpty", "conpty", "", NULL};
+#if defined(WIN3264) && defined(FEAT_TERMINAL)
+static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
 #endif
 
 static void set_options_default(int opt_flags);
@@ -7505,12 +7504,14 @@ did_set_string_option(
 		errmsg = e_invarg;
 	}
     }
-    // 'termmode'
-    else if (varp == &curwin->w_p_tmod)
-    {
-	if (check_opt_strings(*varp, p_tmod_values, FALSE) != OK)
+# if defined(WIN3264)
+    // 'termwintype'
+    else if (varp == &p_twt)
+    {
+	if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
 	    errmsg = e_invarg;
     }
+# endif
 #endif
 
 #ifdef FEAT_VARTABS
@@ -10952,7 +10953,6 @@ get_varp(struct vimoption *p)
 	case PV_TWK:    return (char_u *)&(curwin->w_p_twk);
 	case PV_TWS:    return (char_u *)&(curwin->w_p_tws);
 	case PV_TWSL:	return (char_u *)&(curbuf->b_p_twsl);
-	case PV_TMOD:	return (char_u *)&(curwin->w_p_tmod);
 #endif
 
 	case PV_AI:	return (char_u *)&(curbuf->b_p_ai);
@@ -11153,7 +11153,6 @@ copy_winopt(winopt_T *from, winopt_T *to
 #ifdef FEAT_TERMINAL
     to->wo_twk = vim_strsave(from->wo_twk);
     to->wo_tws = vim_strsave(from->wo_tws);
-    to->wo_tmod = vim_strsave(from->wo_tmod);
 #endif
 #ifdef FEAT_FOLDING
     to->wo_fdc = from->wo_fdc;
@@ -11224,7 +11223,6 @@ check_winopt(winopt_T *wop UNUSED)
 #ifdef FEAT_TERMINAL
     check_string_option(&wop->wo_twk);
     check_string_option(&wop->wo_tws);
-    check_string_option(&wop->wo_tmod);
 #endif
 #ifdef FEAT_LINEBREAK
     check_string_option(&wop->wo_briopt);
@@ -11268,7 +11266,6 @@ clear_winopt(winopt_T *wop UNUSED)
 #ifdef FEAT_TERMINAL
     clear_string_option(&wop->wo_twk);
     clear_string_option(&wop->wo_tws);
-    clear_string_option(&wop->wo_tmod);
 #endif
 }
 
--- a/src/option.h
+++ b/src/option.h
@@ -834,6 +834,9 @@ EXTERN char_u	*p_tenc;	/* 'termencoding'
 #ifdef FEAT_TERMGUICOLORS
 EXTERN int	p_tgc;		/* 'termguicolors' */
 #endif
+#if defined(WIN3264) && defined(FEAT_TERMINAL)
+EXTERN char_u	*p_twt;		// 'termwintype'
+#endif
 EXTERN int	p_terse;	/* 'terse' */
 EXTERN int	p_ta;		/* 'textauto' */
 EXTERN int	p_to;		/* 'tildeop' */
@@ -1112,7 +1115,6 @@ enum
 #ifdef FEAT_TERMINAL
     , WV_TWK
     , WV_TWS
-    , WV_TMOD
 #endif
     , WV_CRBIND
 #ifdef FEAT_LINEBREAK
--- a/src/structs.h
+++ b/src/structs.h
@@ -282,8 +282,6 @@ typedef struct
 # define w_p_twk w_onebuf_opt.wo_twk	/* 'termwinkey' */
     char_u	*wo_tws;
 # define w_p_tws w_onebuf_opt.wo_tws	/* 'termwinsize' */
-    char_u	*wo_tmod;
-# define w_p_tmod w_onebuf_opt.wo_tmod	/* 'termmode' */
 #endif
 
 #ifdef FEAT_EVAL
@@ -1556,6 +1554,9 @@ struct jobvar_S
 #ifdef UNIX
     char_u	*jv_termsig;	/* allocated */
 #endif
+#ifdef WIN3264
+    char_u	*jv_tty_type;	// allocated
+#endif
     int		jv_exitval;
     char_u	*jv_exit_cb;	/* allocated */
     partial_T	*jv_exit_partial;
@@ -1791,7 +1792,7 @@ struct channel_S {
 #define JO2_NORESTORE	    0x2000	/* "norestore" */
 #define JO2_TERM_KILL	    0x4000	/* "term_kill" */
 #define JO2_ANSI_COLORS	    0x8000	/* "ansi_colors" */
-#define JO2_TERM_MODE	    0x10000	/* "term_mode" */
+#define JO2_TTY_TYPE	    0x10000	/* "tty_type" */
 
 #define JO_MODE_ALL	(JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
 #define JO_CB_ALL \
@@ -1864,7 +1865,7 @@ typedef struct
 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
     long_u	jo_ansi_colors[16];
 # endif
-    int		jo_term_mode;	    // first character of "term_mode"
+    int		jo_tty_type;	    // first character of "tty_type"
 #endif
 } jobopt_T;
 
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -742,16 +742,26 @@ ex_terminal(exarg_T *eap)
 	    vim_free(buf);
 	    *p = ' ';
 	}
-	else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "winpty", 6) == 0)
+#ifdef WIN3264
+	else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "type", 4) == 0
+								 && ep != NULL)
 	{
-	    opt.jo_set2 |= JO2_TERM_MODE;
-	    opt.jo_term_mode = 'w';
+	    int tty_type = NUL;
+
+	    p = skiptowhite(cmd);
+	    if (STRNICMP(ep + 1, "winpty", p - (ep + 1)) == 0)
+		tty_type = 'w';
+	    else if (STRNICMP(ep + 1, "conpty", p - (ep + 1)) == 0)
+		tty_type = 'c';
+	    else
+	    {
+		semsg(e_invargval, "type");
+		goto theend;
+	    }
+	    opt.jo_set2 |= JO2_TTY_TYPE;
+	    opt.jo_tty_type = tty_type;
 	}
-	else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "conpty", 6) == 0)
-	{
-	    opt.jo_set2 |= JO2_TERM_MODE;
-	    opt.jo_term_mode = 'c';
-	}
+#endif
 	else
 	{
 	    if (*p)
@@ -809,9 +819,8 @@ term_write_session(FILE *fd, win_T *wp)
 		term->tl_cols, term->tl_rows) < 0)
 	return FAIL;
 #ifdef WIN3264
-    if (*wp->w_p_tmod != NUL)
-	if (fprintf(fd, "++%s ", wp->w_p_tmod) < 0)
-	    return FAIL;
+    if (fprintf(fd, "++type=%s ", term->tl_job->jv_tty_type) < 0)
+	return FAIL;
 #endif
     if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0)
 	return FAIL;
@@ -5369,7 +5378,7 @@ f_term_start(typval_T *argvars, typval_T
 		    + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
 		    + JO2_CWD + JO2_ENV + JO2_EOF_CHARS
 		    + JO2_NORESTORE + JO2_TERM_KILL
-		    + JO2_ANSI_COLORS + JO2_TERM_MODE) == FAIL)
+		    + JO2_ANSI_COLORS + JO2_TTY_TYPE) == FAIL)
 	return;
 
     buf = term_start(&argvars[0], NULL, &opt, 0);
@@ -5713,6 +5722,7 @@ conpty_term_and_job_init(
     job->jv_proc_info = proc_info;
     job->jv_job_object = jo;
     job->jv_status = JOB_STARTED;
+    job->jv_tty_type = vim_strsave("conpty");
     ++job->jv_refcount;
     term->tl_job = job;
 
@@ -6046,6 +6056,7 @@ winpty_term_and_job_init(
 	    (short_u *)winpty_conin_name(term->tl_winpty), NULL);
     job->jv_tty_out = utf16_to_enc(
 	    (short_u *)winpty_conout_name(term->tl_winpty), NULL);
+    job->jv_tty_type = vim_strsave("winpty");
     ++job->jv_refcount;
     term->tl_job = job;
 
@@ -6113,6 +6124,7 @@ term_and_job_init(
 {
     int		    use_winpty = FALSE;
     int		    use_conpty = FALSE;
+    int		    tty_type = *p_twt;
 
     has_winpty = dyn_winpty_init(FALSE) != FAIL ? TRUE : FALSE;
     has_conpty = dyn_conpty_init(FALSE) != FAIL ? TRUE : FALSE;
@@ -6122,14 +6134,10 @@ term_and_job_init(
 	// conpty is not available it can't be installed either.
 	return dyn_winpty_init(TRUE);
 
-    if (opt->jo_term_mode == 'w')
-	set_string_option_direct((char_u *)"tmod", -1, (char_u *)"winpty",
-							OPT_FREE|OPT_LOCAL, 0);
-    if (opt->jo_term_mode == 'c')
-	set_string_option_direct((char_u *)"tmod", -1, (char_u *)"conpty",
-							OPT_FREE|OPT_LOCAL, 0);
-
-    if (curwin->w_p_tmod == NULL || *curwin->w_p_tmod == NUL)
+    if (opt->jo_tty_type != NUL)
+	tty_type = opt->jo_tty_type;
+
+    if (tty_type == NUL)
     {
 	if (has_conpty)
 	    use_conpty = TRUE;
@@ -6137,12 +6145,12 @@ term_and_job_init(
 	    use_winpty = TRUE;
 	// else: error
     }
-    else if (STRICMP(curwin->w_p_tmod, "winpty") == 0)
+    else if (tty_type == 'w')	// winpty
     {
 	if (has_winpty)
 	    use_winpty = TRUE;
     }
-    else if (STRICMP(curwin->w_p_tmod, "conpty") == 0)
+    else if (tty_type == 'c')	// conpty
     {
 	if (has_conpty)
 	    use_conpty = TRUE;
@@ -6151,18 +6159,10 @@ term_and_job_init(
     }
 
     if (use_conpty)
-    {
-	set_string_option_direct((char_u *)"tmod", -1, (char_u *)"conpty",
-							OPT_FREE|OPT_LOCAL, 0);
 	return conpty_term_and_job_init(term, argvar, argv, opt, orig_opt);
-    }
 
     if (use_winpty)
-    {
-	set_string_option_direct((char_u *)"tmod", -1, (char_u *)"winpty",
-							OPT_FREE|OPT_LOCAL, 0);
 	return winpty_term_and_job_init(term, argvar, argv, opt, orig_opt);
-    }
 
     // error
     return dyn_winpty_init(TRUE);
--- a/src/testdir/gen_opt_test.vim
+++ b/src/testdir/gen_opt_test.vim
@@ -131,8 +131,8 @@ let test_values = {
       \ 'term': [[], []],
       \ 'termguicolors': [[], []],
       \ 'termencoding': [has('gui_gtk') ? [] : ['', 'utf-8'], ['xxx']],
-      \ 'termmode': [['', 'winpty', 'conpty'], ['xxx']],
       \ 'termwinsize': [['', '24x80', '0x80', '32x0', '0x0'], ['xxx', '80', '8ax9', '24x80b']],
+      \ 'termwintype': [['', 'winpty', 'conpty'], ['xxx']],
       \ 'toolbar': [['', 'icons', 'text'], ['xxx']],
       \ 'toolbariconsize': [['', 'tiny', 'huge'], ['xxx']],
       \ 'ttymouse': [['', 'xterm'], ['xxx']],
--- a/src/version.c
+++ b/src/version.c
@@ -784,6 +784,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    880,
+/**/
     879,
 /**/
     878,