File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -472,6 +472,9 @@ int mingw_raise(int sig);
472472 * ANSI emulation wrappers
473473 */
474474
475+ int winansi_isatty (int fd );
476+ #define isatty winansi_isatty
477+
475478void winansi_init (void );
476479HANDLE winansi_get_osfhandle (int fd );
477480
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ static void set_interactive(int fd, int bit)
2424
2525#endif
2626
27+ /* In this file, we actually want to use Windows' own isatty(). */
28+ #undef isatty
29+
2730/*
2831 ANSI codes used by git: m, K
2932
@@ -660,6 +663,36 @@ static void detect_msys_tty(int fd)
660663
661664#endif
662665
666+ int winansi_isatty (int fd )
667+ {
668+ int res = isatty (fd );
669+
670+ if (res ) {
671+ /*
672+ * Make sure that /dev/null is not fooling Git into believing
673+ * that we are connected to a terminal, as "_isatty() returns a
674+ * nonzero value if the descriptor is associated with a
675+ * character device."; for more information, see
676+ *
677+ * https://msdn.microsoft.com/en-us/library/f4s0ddew.aspx
678+ */
679+ HANDLE handle = (HANDLE )_get_osfhandle (fd );
680+ if (fd == STDIN_FILENO ) {
681+ DWORD dummy ;
682+
683+ if (!GetConsoleMode (handle , & dummy ))
684+ res = 0 ;
685+ } else if (fd == STDOUT_FILENO || fd == STDERR_FILENO ) {
686+ CONSOLE_SCREEN_BUFFER_INFO dummy ;
687+
688+ if (!GetConsoleScreenBufferInfo (handle , & dummy ))
689+ res = 0 ;
690+ }
691+ }
692+
693+ return res ;
694+ }
695+
663696void winansi_init (void )
664697{
665698 int con1 , con2 ;
You can’t perform that action at this time.
0 commit comments