Permalink
Browse files

patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window

Problem:    $VIM_TERMINAL is also set when not in a terminal window.
Solution:   Pass a flag to indicate whether the job runs in a terminal.
  • Loading branch information...
brammool committed Jun 12, 2018
1 parent d7a137f commit 493359eb3b10377d5c3524e91d911809b8ac7a76
Showing with 66 additions and 33 deletions.
  1. +6 −2 src/channel.c
  2. +1 −1 src/evalfunc.c
  3. +29 −12 src/os_unix.c
  4. +25 −15 src/os_win32.c
  5. +1 −1 src/proto/channel.pro
  6. +1 −1 src/proto/os_unix.pro
  7. +1 −1 src/terminal.c
  8. +2 −0 src/version.c
@@ -5525,7 +5525,11 @@ job_check_ended(void)
* Returns NULL when out of memory.
*/
job_T *
job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
job_start(
typval_T *argvars,
char **argv_arg,
jobopt_T *opt_arg,
int is_terminal UNUSED)
{
job_T *job;
char_u *cmd = NULL;
@@ -5679,7 +5683,7 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
ch_log(NULL, "Starting job: %s", (char *)ga.ga_data);
ga_clear(&ga);
}
mch_job_start(argv, job, &opt);
mch_job_start(argv, job, &opt, is_terminal);
#else
ch_log(NULL, "Starting job: %s", (char *)cmd);
mch_job_start((char *)cmd, job, &opt);
@@ -7254,7 +7254,7 @@ f_job_start(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_JOB;
if (check_restricted() || check_secure())
return;
rettv->vval.v_job = job_start(argvars, NULL, NULL);
rettv->vval.v_job = job_start(argvars, NULL, NULL, FALSE);
}
/*
@@ -4159,7 +4159,11 @@ wait4pid(pid_t child, waitstatus *status)
* Set the environment for a child process.
*/
static void
set_child_environment(long rows, long columns, char *term)
set_child_environment(
long rows,
long columns,
char *term,
int is_terminal UNUSED)
{
# ifdef HAVE_SETENV
char envbuf[50];
@@ -4169,7 +4173,9 @@ set_child_environment(long rows, long columns, char *term)
static char envbuf_Lines[20];
static char envbuf_Columns[20];
static char envbuf_Colors[20];
# ifdef FEAT_TERMINAL
static char envbuf_Version[20];
# endif
# ifdef FEAT_CLIENTSERVER
static char envbuf_Servername[60];
# endif
@@ -4190,8 +4196,13 @@ set_child_environment(long rows, long columns, char *term)
setenv("COLUMNS", (char *)envbuf, 1);
sprintf((char *)envbuf, "%ld", colors);
setenv("COLORS", (char *)envbuf, 1);
sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION));
setenv("VIM_TERMINAL", (char *)envbuf, 1);
# ifdef FEAT_TERMINAL
if (is_terminal)
{
sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION));
setenv("VIM_TERMINAL", (char *)envbuf, 1);
}
# endif
# ifdef FEAT_CLIENTSERVER
setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1);
# endif
@@ -4212,9 +4223,14 @@ set_child_environment(long rows, long columns, char *term)
putenv(envbuf_Columns);
vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors);
putenv(envbuf_Colors);
vim_snprintf(envbuf_Version, sizeof(envbuf_Version), "VIM_TERMINAL=%ld",
get_vim_var_nr(VV_VERSION));
putenv(envbuf_Version);
# ifdef FEAT_TERMINAL
if (is_terminal)
{
vim_snprintf(envbuf_Version, sizeof(envbuf_Version),
"VIM_TERMINAL=%ld", get_vim_var_nr(VV_VERSION));
putenv(envbuf_Version);
}
# endif
# ifdef FEAT_CLIENTSERVER
vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername),
"VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName);
@@ -4224,9 +4240,9 @@ set_child_environment(long rows, long columns, char *term)
}
static void
set_default_child_environment(void)
set_default_child_environment(int is_terminal)
{
set_child_environment(Rows, Columns, "dumb");
set_child_environment(Rows, Columns, "dumb", is_terminal);
}
#endif
@@ -4689,7 +4705,7 @@ mch_call_shell_fork(
# endif
}
# endif
set_default_child_environment();
set_default_child_environment(FALSE);
/*
* stderr is only redirected when using the GUI, so that a
@@ -5367,7 +5383,7 @@ mch_call_shell(
#if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
void
mch_job_start(char **argv, job_T *job, jobopt_T *options)
mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal)
{
pid_t pid;
int fd_in[2] = {-1, -1}; /* for stdin */
@@ -5515,11 +5531,12 @@ mch_job_start(char **argv, job_T *job, jobopt_T *options)
set_child_environment(
(long)options->jo_term_rows,
(long)options->jo_term_cols,
term);
term,
is_terminal);
}
else
# endif
set_default_child_environment();
set_default_child_environment(is_terminal);
if (options->jo_env != NULL)
{
@@ -5275,41 +5275,51 @@ win32_build_env(dict_T *env, garray_T *gap, int is_terminal)
}
}
if (is_terminal)
# if defined(FEAT_CLIENTSERVER) || defined(FEAT_TERMINAL)
{
# ifdef FEAT_CLIENTSERVER
# ifdef FEAT_CLIENTSERVER
char_u *servername = get_vim_var_str(VV_SEND_SERVER);
size_t servername_len = STRLEN(servername);
# endif
# endif
# ifdef FEAT_TERMINAL
char_u *version = get_vim_var_str(VV_VERSION);
size_t version_len = STRLEN(version);
# endif
// size of "VIM_SERVERNAME=" and value,
// plus "VIM_TERMINAL=" and value,
// plus two terminating NULs
size_t n = 0
# ifdef FEAT_CLIENTSERVER
# ifdef FEAT_CLIENTSERVER
+ 15 + servername_len
# endif
+ 13 + version_len + 2;
# endif
# ifdef FEAT_TERMINAL
+ 13 + version_len + 2
# endif
;
if (ga_grow(gap, (int)n) == OK)
{
# ifdef FEAT_CLIENTSERVER
# ifdef FEAT_CLIENTSERVER
for (n = 0; n < 15; n++)
*((WCHAR*)gap->ga_data + gap->ga_len++) =
(WCHAR)"VIM_SERVERNAME="[n];
for (n = 0; n < servername_len; n++)
*((WCHAR*)gap->ga_data + gap->ga_len++) =
(WCHAR)servername[n];
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
# endif
for (n = 0; n < 13; n++)
*((WCHAR*)gap->ga_data + gap->ga_len++) =
(WCHAR)"VIM_TERMINAL="[n];
for (n = 0; n < version_len; n++)
*((WCHAR*)gap->ga_data + gap->ga_len++) =
(WCHAR)version[n];
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
# endif
# ifdef FEAT_TERMINAL
if (is_terminal)
{
for (n = 0; n < 13; n++)
*((WCHAR*)gap->ga_data + gap->ga_len++) =
(WCHAR)"VIM_TERMINAL="[n];
for (n = 0; n < version_len; n++)
*((WCHAR*)gap->ga_data + gap->ga_len++) =
(WCHAR)version[n];
*((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
}
# endif
}
}
}
@@ -66,7 +66,7 @@ void job_set_options(job_T *job, jobopt_T *opt);
void job_stop_on_exit(void);
int has_pending_job(void);
void job_check_ended(void);
job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg);
job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg, int is_terminal);
char *job_status(job_T *job);
void job_info(job_T *job, dict_T *dict);
void job_info_all(list_T *l);
@@ -62,7 +62,7 @@ void mch_set_shellsize(void);
void mch_new_shellsize(void);
void may_send_sigint(int c, pid_t pid, pid_t wpid);
int mch_call_shell(char_u *cmd, int options);
void mch_job_start(char **argv, job_T *job, jobopt_T *options);
void mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal);
char *mch_job_status(job_T *job);
job_T *mch_detect_ended_job(job_T *job_list);
int mch_signal_job(job_T *job, char_u *how);
@@ -5769,7 +5769,7 @@ term_and_job_init(
#endif
/* This may change a string in "argvar". */
term->tl_job = job_start(argvar, argv, opt);
term->tl_job = job_start(argvar, argv, opt, TRUE);
if (term->tl_job != NULL)
++term->tl_job->jv_refcount;
@@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
50,
/**/
49,
/**/

0 comments on commit 493359e

Please sign in to comment.