Skip to content

Commit 5be8dd0

Browse files
committed
patch 8.0.0855: MS-Windows: can't get tty name of terminal
Problem: MS-Windows: can't get tty name of terminal. Solution: Use the winpty process number. (Yasuhiro Matsumoto, closes #1929)
1 parent e9c21ae commit 5be8dd0

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/terminal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,7 @@ void (*winpty_spawn_config_free)(void*);
22012201
void (*winpty_error_free)(void*);
22022202
LPCWSTR (*winpty_error_msg)(void*);
22032203
BOOL (*winpty_set_size)(void*, int, int, void*);
2204+
HANDLE (*winpty_agent_process)(void*);
22042205

22052206
#define WINPTY_DLL "winpty.dll"
22062207

@@ -2230,6 +2231,7 @@ dyn_winpty_init(void)
22302231
{"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
22312232
{"winpty_error_msg", (FARPROC*)&winpty_error_msg},
22322233
{"winpty_set_size", (FARPROC*)&winpty_set_size},
2234+
{"winpty_agent_process", (FARPROC*)&winpty_agent_process},
22332235
{NULL, NULL}
22342236
};
22352237

@@ -2272,6 +2274,7 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd, jobopt_T *opt)
22722274
HANDLE jo = NULL, child_process_handle, child_thread_handle;
22732275
void *winpty_err;
22742276
void *spawn_config = NULL;
2277+
char buf[MAX_PATH];
22752278

22762279
if (!dyn_winpty_init())
22772280
return FAIL;
@@ -2358,6 +2361,9 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd, jobopt_T *opt)
23582361
job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
23592362
job->jv_job_object = jo;
23602363
job->jv_status = JOB_STARTED;
2364+
sprintf(buf, "winpty://%lu",
2365+
GetProcessId(winpty_agent_process(term->tl_winpty)));
2366+
job->jv_tty_name = vim_strsave((char_u*)buf);
23612367
++job->jv_refcount;
23622368
term->tl_job = job;
23632369

src/testdir/test_terminal.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func Test_terminal_basic()
3434
call assert_match("^/dev/", job_info(g:job).tty)
3535
call assert_match("^/dev/", term_gettty(''))
3636
else
37-
call assert_equal("", job_info(g:job).tty)
37+
call assert_match("^winpty://", job_info(g:job).tty)
38+
call assert_match("^winpty://", term_gettty(''))
3839
endif
3940
call Stop_shell_in_terminal(buf)
4041
call term_wait(buf)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
855,
772774
/**/
773775
854,
774776
/**/

0 commit comments

Comments
 (0)