Hi Hannes,

On Sun, 18 Dec 2016, Johannes Sixt wrote:

> What do you think?
> 
> diff --git a/compat/winansi.c b/compat/winansi.c
> index ba360be69b..1748d17777 100644
> --- a/compat/winansi.c
> +++ b/compat/winansi.c
> @@ -575,9 +575,8 @@ static void detect_msys_tty(int fd)
>  
>  int winansi_isatty(int fd)
>  {
> -     int res = isatty(fd);
> -
> -     if (res) {
> +     switch (fd) {
> +     case 0:
>               /*
>                * Make sure that /dev/null is not fooling Git into believing
>                * that we are connected to a terminal, as "_isatty() returns a
> @@ -586,21 +585,19 @@ int winansi_isatty(int fd)
>                *
>                * https://msdn.microsoft.com/en-us/library/f4s0ddew.aspx
>                */
> -             HANDLE handle = winansi_get_osfhandle(fd);
> -             if (fd == STDIN_FILENO) {
> +             {
> +                     HANDLE handle = (HANDLE)_get_osfhandle(fd);
>                       DWORD dummy;
>  
> -                     if (!GetConsoleMode(handle, &dummy))
> -                             res = 0;
> -             } else if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
> -                     CONSOLE_SCREEN_BUFFER_INFO dummy;
> -
> -                     if (!GetConsoleScreenBufferInfo(handle, &dummy))
> -                             res = 0;
> +                     return !!GetConsoleMode(handle, &dummy);
>               }
> +     case 1:
> +             return !!hconsole1;
> +     case 2:
> +             return !!hconsole2;
>       }
>  
> -     return res;
> +     return isatty(fd);
>  }
>  
>  void winansi_init(void)

I think that would break running Git in Git Bash (i.e. MinTTY) ;-)

Let me try to come up with a patch series starting from your patch. We
need

- to abandon the _pioinfo hack

- to make isatty() work correctly with /dev/null

- to make isatty() work correctly in CMD

- to make isatty() work correctly in MinTTY (i.e. with MSYS2 pipes instead
  of Consoles)

I think we can have it all.

Ciao,
Dscho

Reply via email to