Skip to content

Commit 2cab0e1

Browse files
committed
patch 8.0.0096
Problem: When the input or output is not a tty Vim appears to hang. Solution: Add the --ttyfail argument. Also add the "ttyin" and "ttyout" features to be able to check in Vim script.
1 parent 182707a commit 2cab0e1

7 files changed

Lines changed: 25 additions & 5 deletions

File tree

runtime/doc/eval.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8416,6 +8416,8 @@ tgetent Compiled with tgetent support, able to use a termcap
84168416
timers Compiled with |timer_start()| support.
84178417
title Compiled with window title support |'title'|.
84188418
toolbar Compiled with support for |gui-toolbar|.
8419+
ttyin input is a terminal (tty)
8420+
ttyout output is a terminal (tty)
84198421
unix Unix version of Vim.
84208422
user_commands User-defined commands.
84218423
vertsplit Compiled with vertically split windows |:vsplit|.

runtime/doc/starting.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ a slash. Thus "-R" means recovery and "-/R" readonly.
421421
not connected to a terminal. This will avoid the warning and
422422
the two second delay that would happen. {not in Vi}
423423

424+
*--ttyfail*
425+
--ttyfail When the stdin or stdout is not a terminal (tty) then exit
426+
right away.
427+
424428
*-d*
425429
-d Start in diff mode, like |vimdiff|.
426430
{not in Vi} {not available when compiled without the |+diff|

src/evalfunc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5959,6 +5959,10 @@ f_has(typval_T *argvars, typval_T *rettv)
59595959
}
59605960
else if (STRICMP(name, "vim_starting") == 0)
59615961
n = (starting != 0);
5962+
else if (STRICMP(name, "ttyin") == 0)
5963+
n = mch_input_isatty();
5964+
else if (STRICMP(name, "ttyout") == 0)
5965+
n = stdout_isatty;
59625966
#ifdef FEAT_MBYTE
59635967
else if (STRICMP(name, "multi_byte_encoding") == 0)
59645968
n = has_mbyte;

src/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ EXTERN int exiting INIT(= FALSE);
643643
EXTERN int really_exiting INIT(= FALSE);
644644
/* TRUE when we are sure to exit, e.g., after
645645
* a deadly signal */
646+
EXTERN int stdout_isatty INIT(= TRUE); /* is stdout a terminal? */
647+
646648
#if defined(FEAT_AUTOCHDIR)
647649
EXTERN int test_autochdir INIT(= FALSE);
648650
#endif

src/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ common_init(mparm_T *paramp)
973973
* (needed for :! to * work). mch_check_win() will also handle the -d or
974974
* -dev argument.
975975
*/
976-
paramp->stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
976+
stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
977977
TIME_MSG("window checked");
978978

979979
/*
@@ -1828,6 +1828,7 @@ command_line_scan(mparm_T *parmp)
18281828
/* "--literal" take files literally */
18291829
/* "--nofork" don't fork */
18301830
/* "--not-a-term" don't warn for not a term */
1831+
/* "--ttyfail" exit if not a term */
18311832
/* "--noplugin[s]" skip plugins */
18321833
/* "--cmd <cmd>" execute cmd before vimrc */
18331834
if (STRICMP(argv[0] + argv_idx, "help") == 0)
@@ -1857,6 +1858,8 @@ command_line_scan(mparm_T *parmp)
18571858
p_lpl = FALSE;
18581859
else if (STRNICMP(argv[0] + argv_idx, "not-a-term", 10) == 0)
18591860
parmp->not_a_term = TRUE;
1861+
else if (STRNICMP(argv[0] + argv_idx, "ttyfail", 7) == 0)
1862+
parmp->tty_fail = TRUE;
18601863
else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0)
18611864
{
18621865
want_argument = TRUE;
@@ -2489,7 +2492,7 @@ check_tty(mparm_T *parmp)
24892492
if (!input_isatty)
24902493
silent_mode = TRUE;
24912494
}
2492-
else if (parmp->want_full_screen && (!parmp->stdout_isatty || !input_isatty)
2495+
else if (parmp->want_full_screen && (!stdout_isatty || !input_isatty)
24932496
#ifdef FEAT_GUI
24942497
/* don't want the delay when started from the desktop */
24952498
&& !gui.starting
@@ -2504,7 +2507,7 @@ check_tty(mparm_T *parmp)
25042507
* input buffer so fast I can't even kill the process in under 2
25052508
* minutes (and it beeps continuously the whole time :-)
25062509
*/
2507-
if (netbeans_active() && (!parmp->stdout_isatty || !input_isatty))
2510+
if (netbeans_active() && (!stdout_isatty || !input_isatty))
25082511
{
25092512
mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n"));
25102513
exit(1);
@@ -2517,11 +2520,13 @@ check_tty(mparm_T *parmp)
25172520
exit(1);
25182521
}
25192522
#endif
2520-
if (!parmp->stdout_isatty)
2523+
if (!stdout_isatty)
25212524
mch_errmsg(_("Vim: Warning: Output is not to a terminal\n"));
25222525
if (!input_isatty)
25232526
mch_errmsg(_("Vim: Warning: Input is not from a terminal\n"));
25242527
out_flush();
2528+
if (parmp->tty_fail && (!stdout_isatty || !input_isatty))
2529+
exit(1);
25252530
if (scriptin[0] == NULL)
25262531
ui_delay(2000L, TRUE);
25272532
TIME_MSG("Warning delay");
@@ -3287,6 +3292,7 @@ usage(void)
32873292
#endif
32883293
main_msg(_("-T <terminal>\tSet terminal type to <terminal>"));
32893294
main_msg(_("--not-a-term\t\tSkip warning for input/output not being a terminal"));
3295+
main_msg(_("--ttyfail\t\tExit if input or output is not a terminal"));
32903296
main_msg(_("-u <vimrc>\t\tUse <vimrc> instead of any .vimrc"));
32913297
#ifdef FEAT_GUI
32923298
main_msg(_("-U <gvimrc>\t\tUse <gvimrc> instead of any .gvimrc"));

src/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,8 +3225,8 @@ typedef struct
32253225
#endif
32263226

32273227
int want_full_screen;
3228-
int stdout_isatty; /* is stdout a terminal? */
32293228
int not_a_term; /* no warning for missing term? */
3229+
int tty_fail; /* exit if not a tty */
32303230
char_u *term; /* specified terminal name */
32313231
#ifdef FEAT_CRYPT
32323232
int ask_for_key; /* -x argument */

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
96,
767769
/**/
768770
95,
769771
/**/

0 commit comments

Comments
 (0)