3838 * in tl_scrollback are no longer used.
3939 *
4040 * TODO:
41- * - ":term NONE" does not work on MS-Windows.
42- * https://github.com/vim/vim/pull/2056
41+ * - patch to use GUI or cterm colors for vterm. Yasuhiro, #2067
4342 * - Redirecting output does not work on MS-Windows.
4443 * - implement term_setsize()
4544 * - add test for giving error for invalid 'termsize' value.
@@ -97,7 +96,8 @@ struct terminal_S {
9796
9897 /* used when tl_job is NULL and only a pty was created */
9998 int tl_tty_fd ;
100- char_u * tl_tty_name ;
99+ char_u * tl_tty_in ;
100+ char_u * tl_tty_out ;
101101
102102 int tl_normal_mode ; /* TRUE: Terminal-Normal mode */
103103 int tl_channel_closed ;
@@ -2666,14 +2666,32 @@ f_term_gettty(typval_T *argvars, typval_T *rettv)
26662666{
26672667 buf_T * buf = term_get_buf (argvars );
26682668 char_u * p ;
2669+ int num = 0 ;
26692670
26702671 rettv -> v_type = VAR_STRING ;
26712672 if (buf == NULL )
26722673 return ;
2673- if (buf -> b_term -> tl_job != NULL )
2674- p = buf -> b_term -> tl_job -> jv_tty_name ;
2675- else
2676- p = buf -> b_term -> tl_tty_name ;
2674+ if (argvars [1 ].v_type != VAR_UNKNOWN )
2675+ num = get_tv_number (& argvars [1 ]);
2676+
2677+ switch (num )
2678+ {
2679+ case 0 :
2680+ if (buf -> b_term -> tl_job != NULL )
2681+ p = buf -> b_term -> tl_job -> jv_tty_out ;
2682+ else
2683+ p = buf -> b_term -> tl_tty_out ;
2684+ break ;
2685+ case 1 :
2686+ if (buf -> b_term -> tl_job != NULL )
2687+ p = buf -> b_term -> tl_job -> jv_tty_in ;
2688+ else
2689+ p = buf -> b_term -> tl_tty_in ;
2690+ break ;
2691+ default :
2692+ EMSG2 (_ (e_invarg2 ), get_tv_string (& argvars [1 ]));
2693+ return ;
2694+ }
26772695 if (p != NULL )
26782696 rettv -> vval .v_string = vim_strsave (p );
26792697}
@@ -3055,7 +3073,6 @@ term_and_job_init(
30553073 HANDLE child_thread_handle ;
30563074 void * winpty_err ;
30573075 void * spawn_config = NULL ;
3058- char buf [MAX_PATH ];
30593076 garray_T ga ;
30603077 char_u * cmd ;
30613078
@@ -3094,7 +3111,6 @@ term_and_job_init(
30943111 if (term -> tl_winpty == NULL )
30953112 goto failed ;
30963113
3097- /* TODO: if the command is "NONE" only create a pty. */
30983114 spawn_config = winpty_spawn_config_new (
30993115 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
31003116 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN ,
@@ -3162,9 +3178,10 @@ term_and_job_init(
31623178 job -> jv_proc_info .dwProcessId = GetProcessId (child_process_handle );
31633179 job -> jv_job_object = jo ;
31643180 job -> jv_status = JOB_STARTED ;
3165- sprintf (buf , "winpty://%lu" ,
3166- GetProcessId (winpty_agent_process (term -> tl_winpty )));
3167- job -> jv_tty_name = vim_strsave ((char_u * )buf );
3181+ job -> jv_tty_in = utf16_to_enc (
3182+ (short_u * )winpty_conin_name (term -> tl_winpty ), NULL );
3183+ job -> jv_tty_out = utf16_to_enc (
3184+ (short_u * )winpty_conout_name (term -> tl_winpty ), NULL );
31683185 ++ job -> jv_refcount ;
31693186 term -> tl_job = job ;
31703187
@@ -3205,9 +3222,68 @@ term_and_job_init(
32053222}
32063223
32073224 static int
3208- create_pty_only (term_T * term , jobopt_T * opt )
3225+ create_pty_only (term_T * term , jobopt_T * options )
32093226{
3210- /* TODO: implement this */
3227+ HANDLE hPipeIn = INVALID_HANDLE_VALUE ;
3228+ HANDLE hPipeOut = INVALID_HANDLE_VALUE ;
3229+ char in_name [80 ], out_name [80 ];
3230+ channel_T * channel = NULL ;
3231+
3232+ create_vterm (term , term -> tl_rows , term -> tl_cols );
3233+
3234+ vim_snprintf (in_name , sizeof (in_name ), "\\\\.\\pipe\\vim-%d-in-%d" ,
3235+ GetCurrentProcessId (),
3236+ curbuf -> b_fnum );
3237+ hPipeIn = CreateNamedPipe (in_name , PIPE_ACCESS_OUTBOUND ,
3238+ PIPE_TYPE_MESSAGE | PIPE_NOWAIT ,
3239+ PIPE_UNLIMITED_INSTANCES ,
3240+ 0 , 0 , NMPWAIT_NOWAIT , NULL );
3241+ if (hPipeIn == INVALID_HANDLE_VALUE )
3242+ goto failed ;
3243+
3244+ vim_snprintf (out_name , sizeof (out_name ), "\\\\.\\pipe\\vim-%d-out-%d" ,
3245+ GetCurrentProcessId (),
3246+ curbuf -> b_fnum );
3247+ hPipeOut = CreateNamedPipe (out_name , PIPE_ACCESS_INBOUND ,
3248+ PIPE_TYPE_MESSAGE | PIPE_NOWAIT ,
3249+ PIPE_UNLIMITED_INSTANCES ,
3250+ 0 , 0 , 0 , NULL );
3251+ if (hPipeOut == INVALID_HANDLE_VALUE )
3252+ goto failed ;
3253+
3254+ ConnectNamedPipe (hPipeIn , NULL );
3255+ ConnectNamedPipe (hPipeOut , NULL );
3256+
3257+ term -> tl_job = job_alloc ();
3258+ if (term -> tl_job == NULL )
3259+ goto failed ;
3260+ ++ term -> tl_job -> jv_refcount ;
3261+
3262+ /* behave like the job is already finished */
3263+ term -> tl_job -> jv_status = JOB_FINISHED ;
3264+
3265+ channel = add_channel ();
3266+ if (channel == NULL )
3267+ goto failed ;
3268+ term -> tl_job -> jv_channel = channel ;
3269+ channel -> ch_keep_open = TRUE;
3270+ channel -> ch_named_pipe = TRUE;
3271+
3272+ channel_set_pipes (channel ,
3273+ (sock_T )hPipeIn ,
3274+ (sock_T )hPipeOut ,
3275+ (sock_T )hPipeOut );
3276+ channel_set_job (channel , term -> tl_job , options );
3277+ term -> tl_job -> jv_tty_in = vim_strsave ((char_u * )in_name );
3278+ term -> tl_job -> jv_tty_out = vim_strsave ((char_u * )out_name );
3279+
3280+ return OK ;
3281+
3282+ failed :
3283+ if (hPipeIn != NULL )
3284+ CloseHandle (hPipeIn );
3285+ if (hPipeOut != NULL )
3286+ CloseHandle (hPipeOut );
32113287 return FAIL ;
32123288}
32133289
@@ -3234,7 +3310,8 @@ term_free_vterm(term_T *term)
32343310 static void
32353311term_report_winsize (term_T * term , int rows , int cols )
32363312{
3237- winpty_set_size (term -> tl_winpty , cols , rows , NULL );
3313+ if (term -> tl_winpty )
3314+ winpty_set_size (term -> tl_winpty , cols , rows , NULL );
32383315}
32393316
32403317 int
0 commit comments