File tree 2 files changed +36
-0
lines changed 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);
472
472
* ANSI emulation wrappers
473
473
*/
474
474
475
+ int winansi_isatty (int fd );
476
+ #define isatty winansi_isatty
477
+
475
478
void winansi_init (void );
476
479
HANDLE winansi_get_osfhandle (int fd );
477
480
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ static void set_interactive(int fd, int bit)
24
24
25
25
#endif
26
26
27
+ /* In this file, we actually want to use Windows' own isatty(). */
28
+ #undef isatty
29
+
27
30
/*
28
31
ANSI codes used by git: m, K
29
32
@@ -660,6 +663,36 @@ static void detect_msys_tty(int fd)
660
663
661
664
#endif
662
665
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
+
663
696
void winansi_init (void )
664
697
{
665
698
int con1 , con2 ;
You can’t perform that action at this time.
0 commit comments