]> granicus.if.org Git - vim/commitdiff
patch 8.0.0096 v8.0.0096
authorBram Moolenaar <Bram@vim.org>
Thu, 24 Nov 2016 14:09:07 +0000 (15:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 24 Nov 2016 14:09:07 +0000 (15:09 +0100)
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.

runtime/doc/eval.txt
runtime/doc/starting.txt
src/evalfunc.c
src/globals.h
src/main.c
src/structs.h
src/version.c

index b34bf480870163b23ee205ffccec93275f0236b8..1a11a41411020b2650e51b2644e85bb952711aa4 100644 (file)
@@ -8416,6 +8416,8 @@ tgetent                   Compiled with tgetent support, able to use a termcap
 timers                 Compiled with |timer_start()| support.
 title                  Compiled with window title support |'title'|.
 toolbar                        Compiled with support for |gui-toolbar|.
+ttyin                  input is a terminal (tty)
+ttyout                 output is a terminal (tty)
 unix                   Unix version of Vim.
 user_commands          User-defined commands.
 vertsplit              Compiled with vertically split windows |:vsplit|.
index 8ce3c63d2a6b0e978b11ca495d15ff2cb1c034c7..34500fc0ce525735d37d706880363b7fe211d9fc 100644 (file)
@@ -421,6 +421,10 @@ a slash.  Thus "-R" means recovery and "-/R" readonly.
                not connected to a terminal.  This will avoid the warning and
                the two second delay that would happen. {not in Vi}
 
+                                                       *--ttyfail*
+--ttyfail      When the stdin or stdout is not a terminal (tty) then exit
+               right away.
+
                                                        *-d*
 -d             Start in diff mode, like |vimdiff|.
                {not in Vi} {not available when compiled without the |+diff|
index 1257aa0594a0f39b1643ba7c5160fdec52151b7c..846a914165c0e5eb600a7710c9b36ac1f613c270 100644 (file)
@@ -5959,6 +5959,10 @@ f_has(typval_T *argvars, typval_T *rettv)
        }
        else if (STRICMP(name, "vim_starting") == 0)
            n = (starting != 0);
+       else if (STRICMP(name, "ttyin") == 0)
+           n = mch_input_isatty();
+       else if (STRICMP(name, "ttyout") == 0)
+           n = stdout_isatty;
 #ifdef FEAT_MBYTE
        else if (STRICMP(name, "multi_byte_encoding") == 0)
            n = has_mbyte;
index c15e4f9bb997f8ce656d2a74a5a3c3a4ae385e2a..0b6abb0e85ce47fb6b49960cc18f7db5ed82ce59 100644 (file)
@@ -643,6 +643,8 @@ EXTERN int  exiting INIT(= FALSE);
 EXTERN int     really_exiting INIT(= FALSE);
                                /* TRUE when we are sure to exit, e.g., after
                                 * a deadly signal */
+EXTERN int     stdout_isatty INIT(= TRUE);     /* is stdout a terminal? */
+
 #if defined(FEAT_AUTOCHDIR)
 EXTERN int     test_autochdir INIT(= FALSE);
 #endif
index acc51f182abc98d68198886b982c30f9d32d6915..f3c471a85270c2e685d821e11b67ed1207bca544 100644 (file)
@@ -973,7 +973,7 @@ common_init(mparm_T *paramp)
      * (needed for :! to * work). mch_check_win() will also handle the -d or
      * -dev argument.
      */
-    paramp->stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
+    stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
     TIME_MSG("window checked");
 
     /*
@@ -1828,6 +1828,7 @@ command_line_scan(mparm_T *parmp)
                                /* "--literal" take files literally */
                                /* "--nofork" don't fork */
                                /* "--not-a-term" don't warn for not a term */
+                               /* "--ttyfail" exit if not a term */
                                /* "--noplugin[s]" skip plugins */
                                /* "--cmd <cmd>" execute cmd before vimrc */
                if (STRICMP(argv[0] + argv_idx, "help") == 0)
@@ -1857,6 +1858,8 @@ command_line_scan(mparm_T *parmp)
                    p_lpl = FALSE;
                else if (STRNICMP(argv[0] + argv_idx, "not-a-term", 10) == 0)
                    parmp->not_a_term = TRUE;
+               else if (STRNICMP(argv[0] + argv_idx, "ttyfail", 7) == 0)
+                   parmp->tty_fail = TRUE;
                else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0)
                {
                    want_argument = TRUE;
@@ -2489,7 +2492,7 @@ check_tty(mparm_T *parmp)
        if (!input_isatty)
            silent_mode = TRUE;
     }
-    else if (parmp->want_full_screen && (!parmp->stdout_isatty || !input_isatty)
+    else if (parmp->want_full_screen && (!stdout_isatty || !input_isatty)
 #ifdef FEAT_GUI
            /* don't want the delay when started from the desktop */
            && !gui.starting
@@ -2504,7 +2507,7 @@ check_tty(mparm_T *parmp)
         * input buffer so fast I can't even kill the process in under 2
         * minutes (and it beeps continuously the whole time :-)
         */
-       if (netbeans_active() && (!parmp->stdout_isatty || !input_isatty))
+       if (netbeans_active() && (!stdout_isatty || !input_isatty))
        {
            mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n"));
            exit(1);
@@ -2517,11 +2520,13 @@ check_tty(mparm_T *parmp)
            exit(1);
        }
 #endif
-       if (!parmp->stdout_isatty)
+       if (!stdout_isatty)
            mch_errmsg(_("Vim: Warning: Output is not to a terminal\n"));
        if (!input_isatty)
            mch_errmsg(_("Vim: Warning: Input is not from a terminal\n"));
        out_flush();
+       if (parmp->tty_fail && (!stdout_isatty || !input_isatty))
+           exit(1);
        if (scriptin[0] == NULL)
            ui_delay(2000L, TRUE);
        TIME_MSG("Warning delay");
@@ -3287,6 +3292,7 @@ usage(void)
 #endif
     main_msg(_("-T <terminal>\tSet terminal type to <terminal>"));
     main_msg(_("--not-a-term\t\tSkip warning for input/output not being a terminal"));
+    main_msg(_("--ttyfail\t\tExit if input or output is not a terminal"));
     main_msg(_("-u <vimrc>\t\tUse <vimrc> instead of any .vimrc"));
 #ifdef FEAT_GUI
     main_msg(_("-U <gvimrc>\t\tUse <gvimrc> instead of any .gvimrc"));
index c749a3691dde14ed540c014cb5918838a699644b..1b73e37c28ecb6329ac57bf0fe5a1d3a38663311 100644 (file)
@@ -3225,8 +3225,8 @@ typedef struct
 #endif
 
     int                want_full_screen;
-    int                stdout_isatty;          /* is stdout a terminal? */
     int                not_a_term;             /* no warning for missing term? */
+    int                tty_fail;               /* exit if not a tty */
     char_u     *term;                  /* specified terminal name */
 #ifdef FEAT_CRYPT
     int                ask_for_key;            /* -x argument */
index 731a6850d4befb76dac5df0e4f99e53fcd464acd..e259000c0fc5ed368e4d18a04cef7a5dcc63687f 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    96,
 /**/
     95,
 /**/