Skip to content

Commit d7a137f

Browse files
committed
patch 8.1.0049: shell cannot tell running in a terminal window
Problem: Shell cannot tell running in a terminal window. Solution: Add the VIM_TERMINAL environment variable. (Christian Brabandt)
1 parent 07ccf7c commit d7a137f

5 files changed

Lines changed: 44 additions & 10 deletions

File tree

runtime/doc/terminal.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ Environment variables are used to pass information to the running job:
376376
COLUMNS number of columns in the terminal initially
377377
COLORS number of colors, 't_Co' (256*256*256 in the GUI)
378378
VIM_SERVERNAME v:servername
379+
VIM_TERMINAL v:version
379380

380381

381382
MS-Windows ~

src/os_unix.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,6 +4169,7 @@ set_child_environment(long rows, long columns, char *term)
41694169
static char envbuf_Lines[20];
41704170
static char envbuf_Columns[20];
41714171
static char envbuf_Colors[20];
4172+
static char envbuf_Version[20];
41724173
# ifdef FEAT_CLIENTSERVER
41734174
static char envbuf_Servername[60];
41744175
# endif
@@ -4189,6 +4190,8 @@ set_child_environment(long rows, long columns, char *term)
41894190
setenv("COLUMNS", (char *)envbuf, 1);
41904191
sprintf((char *)envbuf, "%ld", colors);
41914192
setenv("COLORS", (char *)envbuf, 1);
4193+
sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION));
4194+
setenv("VIM_TERMINAL", (char *)envbuf, 1);
41924195
# ifdef FEAT_CLIENTSERVER
41934196
setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1);
41944197
# endif
@@ -4209,6 +4212,9 @@ set_child_environment(long rows, long columns, char *term)
42094212
putenv(envbuf_Columns);
42104213
vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors);
42114214
putenv(envbuf_Colors);
4215+
vim_snprintf(envbuf_Version, sizeof(envbuf_Version), "VIM_TERMINAL=%ld",
4216+
get_vim_var_nr(VV_VERSION));
4217+
putenv(envbuf_Version);
42124218
# ifdef FEAT_CLIENTSERVER
42134219
vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername),
42144220
"VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName);

src/os_win32.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5275,25 +5275,43 @@ win32_build_env(dict_T *env, garray_T *gap, int is_terminal)
52755275
}
52765276
}
52775277

5278-
# ifdef FEAT_CLIENTSERVER
52795278
if (is_terminal)
52805279
{
5280+
# ifdef FEAT_CLIENTSERVER
52815281
char_u *servername = get_vim_var_str(VV_SEND_SERVER);
5282-
size_t lval = STRLEN(servername);
5283-
size_t n;
5282+
size_t servername_len = STRLEN(servername);
5283+
# endif
5284+
char_u *version = get_vim_var_str(VV_VERSION);
5285+
size_t version_len = STRLEN(version);
5286+
// size of "VIM_SERVERNAME=" and value,
5287+
// plus "VIM_TERMINAL=" and value,
5288+
// plus two terminating NULs
5289+
size_t n = 0
5290+
# ifdef FEAT_CLIENTSERVER
5291+
+ 15 + servername_len
5292+
# endif
5293+
+ 13 + version_len + 2;
52845294

5285-
if (ga_grow(gap, (int)(14 + lval + 2)) == OK)
5295+
if (ga_grow(gap, (int)n) == OK)
52865296
{
5297+
# ifdef FEAT_CLIENTSERVER
52875298
for (n = 0; n < 15; n++)
52885299
*((WCHAR*)gap->ga_data + gap->ga_len++) =
52895300
(WCHAR)"VIM_SERVERNAME="[n];
5290-
for (n = 0; n < lval; n++)
5301+
for (n = 0; n < servername_len; n++)
52915302
*((WCHAR*)gap->ga_data + gap->ga_len++) =
52925303
(WCHAR)servername[n];
52935304
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
5305+
# endif
5306+
for (n = 0; n < 13; n++)
5307+
*((WCHAR*)gap->ga_data + gap->ga_len++) =
5308+
(WCHAR)"VIM_TERMINAL="[n];
5309+
for (n = 0; n < version_len; n++)
5310+
*((WCHAR*)gap->ga_data + gap->ga_len++) =
5311+
(WCHAR)version[n];
5312+
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
52945313
}
52955314
}
5296-
# endif
52975315
}
52985316

52995317
void

src/testdir/test_terminal.vim

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,18 +482,25 @@ func Test_terminal_servername()
482482
if !has('clientserver')
483483
return
484484
endif
485+
call s:test_environment("VIM_SERVERNAME", v:servername)
486+
endfunc
487+
488+
func Test_terminal_version()
489+
call s:test_environment("VIM_TERMINAL", string(v:version))
490+
endfunc
491+
492+
func s:test_environment(name, value)
485493
let buf = Run_shell_in_terminal({})
486494
" Wait for the shell to display a prompt
487495
call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
488496
if has('win32')
489-
call term_sendkeys(buf, "echo %VIM_SERVERNAME%\r")
497+
call term_sendkeys(buf, "echo %" . a:name . "%\r")
490498
else
491-
call term_sendkeys(buf, "echo $VIM_SERVERNAME\r")
499+
call term_sendkeys(buf, "echo $" . a:name . "\r")
492500
endif
493501
call term_wait(buf)
494502
call Stop_shell_in_terminal(buf)
495-
call WaitFor('getline(2) == v:servername')
496-
call assert_equal(v:servername, getline(2))
503+
call WaitForAssert({-> assert_equal(a:value, getline(2))})
497504

498505
exe buf . 'bwipe'
499506
unlet buf

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
49,
764766
/**/
765767
48,
766768
/**/

0 commit comments

Comments
 (0)