[Libguestfs] [PATCH nbdkit v3 2/6] server: debug: Don't emit ANSI colour codes on Windows

Eric Blake eblake at redhat.com
Tue May 9 18:06:50 UTC 2023


On Tue, May 09, 2023 at 03:51:17PM +0100, Richard W.M. Jones wrote:
> At least under Wine they are not recognized and you just see literal
> "[0m" etc appearing in the output.

Maybe that means the problem is that isatty() under Wine is returning
1 even when it shouldn't?  But avoiding the tty magic on Windows is
fine, whether or not Wine is faithfully reproducing native windows or
has its own problems.

> 
> Updates: commit 5a011e02375912f2ad88de1ebc6d609e29d38f71
> Reviewed-by: Laszlo Ersek <lersek at redhat.com>
> ---
>  server/debug.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/server/debug.c b/server/debug.c
> index 1b5ddaafe..2231d40a0 100644
> --- a/server/debug.c
> +++ b/server/debug.c
> @@ -70,7 +70,9 @@ static void
>  debug_common (bool in_server, const char *fs, va_list args)
>  {
>    int err = errno;
> +#ifndef WIN32
>    int tty;
> +#endif

Could also do unconditional here:

int tty = 0;

>    CLEANUP_FREE char *str = NULL;
>    size_t len = 0;
>    FILE *fp;
> @@ -88,15 +90,19 @@ debug_common (bool in_server, const char *fs, va_list args)
>      return;
>    }
>  
> +#ifndef WIN32
>    tty = isatty (fileno (stderr));
>    if (!in_server && tty) ansi_force_colour (ANSI_FG_BOLD_BLACK, fp);
> +#endif

and here, do:

#ifndef WIN32
  tty = isatty (fileno (stderr));
#endif
  if (...)

>  
>    prologue (fp);
>  
>    errno = err;
>    vfprintf (fp, fs, args);
>  
> +#ifndef WIN32
>    if (!in_server && tty) ansi_force_restore (fp);
> +#endif

and this one can also be unconditional.

But what you have works too, so I'm fine either way.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


More information about the Libguestfs mailing list