BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform

Lists: pgsql-bugspgsql-hackers
From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com
Subject: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2019-11-12 08:29:10
Message-ID: 16108-134692e97146b7bc@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

The following bug has been logged on the website:

Bug reference: 16108
Logged by: Haiying Tang
Email address: tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com
PostgreSQL version: 12.0
Operating system: Windows
Description:

Hello

I found the following release notes in PG12 is not working properly at
Windows.
> •Add colorization to the output of command-line utilities

Following the release note, I've set the the environment variable PG_COLOR
to auto, then I run pg_dump command with an incorrect passwd.
However, the command-line output is not colorized as the release notes
said.

Before PG_COLOR=auto is set: pg_dump: error: connection to database
"tanghy.fnst" failed: FATAL:
After PG_COLOR=auto is set: pg_dump: error: connection
to database "tanghy.fnst" failed: FATAL

I think the colorization to the output of command-line is not supported at
Windows.
Maybe function "pg_logging_init" at source "src\common\logging.c" should add
a platform check.
Besides, the related release note of PG12 should add some description about
it.

Best Regards,
Tang


From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: PG Bug reporting form <noreply(at)postgresql(dot)org>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>, tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2019-11-12 08:39:17
Message-ID: CA+hUKG+Em5CO27qk4PC9syK+p2n0a0ULP_Vm3OqpvdXGQTn0=A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Nov 12, 2019 at 9:30 PM PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 16108
> Logged by: Haiying Tang
> Email address: tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com
> PostgreSQL version: 12.0
> Operating system: Windows
> Description:
>
> Hello
>
> I found the following release notes in PG12 is not working properly at
> Windows.
> > •Add colorization to the output of command-line utilities
>
> Following the release note, I've set the the environment variable PG_COLOR
> to auto, then I run pg_dump command with an incorrect passwd.
> However, the command-line output is not colorized as the release notes
> said.
>
> Before PG_COLOR=auto is set: pg_dump: error: connection to database
> "tanghy.fnst" failed: FATAL:
> After PG_COLOR=auto is set: [01mpg_dump: [0m [01;31merror: [0mconnection
> to database "tanghy.fnst" failed: FATAL
>
> I think the colorization to the output of command-line is not supported at
> Windows.
> Maybe function "pg_logging_init" at source "src\common\logging.c" should add
> a platform check.
> Besides, the related release note of PG12 should add some description about
> it.

Based on this:

https://en.wikipedia.org/wiki/ANSI_escape_code#DOS_and_Windows

... I wonder if it works if you use the new Windows Terminal, and I
wonder if it would work on the older thing if we used the
SetConsoleMode() flag it mentions.


From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PG Bug reporting form <noreply(at)postgresql(dot)org>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>, tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2019-11-12 18:59:35
Message-ID: CAC+AXB2LDsO_vB-yNW8b9VBW=onGPwJiUuxAQ23TDcm8JbJ8NQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Nov 12, 2019 at 9:39 AM Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:

>
> ... I wonder if it works if you use the new Windows Terminal, and I
> wonder if it would work on the older thing if we used the
> SetConsoleMode() flag it mentions.
>
>
In order to make it work both things are needed, setting the console mode
and a terminal that supports it. Please find attached a patch for so.

Regards,

Juan José Santamaría Flecha

Attachment Content-Type Size
0001-command-line-colorization-on-windows.patch application/octet-stream 1.1 KB

From: "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PG Bug reporting form <noreply(at)postgresql(dot)org>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: RE: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2019-11-15 04:23:01
Message-ID: 43AA0560298D1A4893896FDC52840EA1D9C74F7D@G08CNEXMBPEKD03.g08.fujitsu.local
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

>In order to make it work both things are needed, setting the console mode and a terminal that supports it.

Your patch worked fine on windows which supports VT100. But the bug still happened when set PG_COLOR="always" at Windows Terminal that not support VT100. Please see the attached file “Test_result.png” for the NG result. (I used win7 for this test)

To fix the above bug, I made some change to your patch. The new one works fine on my win7(VT100 not support) and win10(VT100 support).

Also, in this new patch(v1), I added some doc change for Windows not support Colorization. Please find the attached patch for so.

Regards,
Tang

From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Sent: Wednesday, November 13, 2019 4:00 AM
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PG Bug reporting form <noreply(at)postgresql(dot)org>; PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>; Tang, Haiying/唐 海英 <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform

On Tue, Nov 12, 2019 at 9:39 AM Thomas Munro <thomas(dot)munro(at)gmail(dot)com<mailto:thomas(dot)munro(at)gmail(dot)com>> wrote:

... I wonder if it works if you use the new Windows Terminal, and I
wonder if it would work on the older thing if we used the
SetConsoleMode() flag it mentions.

In order to make it work both things are needed, setting the console mode and a terminal that supports it. Please find attached a patch for so.

Regards,

Juan José Santamaría Flecha

Attachment Content-Type Size
v1-0001-command-line-colorization-on-windows.patch application/octet-stream 1.6 KB
Test_result.png image/png 86.8 KB

From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PG Bug reporting form <noreply(at)postgresql(dot)org>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2019-11-15 08:14:59
Message-ID: CAC+AXB1yZXb_=DzRoPV8jY0cUX5EFYLHtmOgu7is3d3M31GppQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Thanks for testing. I am opening a new item in the next commitfest for this
topic.

On Fri, Nov 15, 2019 at 5:23 AM Tang, Haiying <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>
wrote:

> >In order to make it work both things are needed, setting the console mode
> and a terminal that supports it.
>
>
>
> Your patch worked fine on windows which supports VT100. But the bug still
> happened when set PG_COLOR="always" at Windows Terminal that not support
> VT100. Please see the attached file “Test_result.png” for the NG result. (I
> used win7 for this test)
>
>
> To fix the above bug, I made some change to your patch. The new one works
> fine on my win7(VT100 not support) and win10(VT100 support).
>

My understanding of the "always" logic is that it has to be enabled no
matter what, even if not supported in current output.

Also, in this new patch(v1), I added some doc change for Windows not
> support Colorization. Please find the attached patch for so.
>
>
>
You cannot change the release notes, if anything it will be added to 12.2
patch notes. It should be added to the 21 (!) utilities that specify the
PG_COLOR usage, but I am not so sure that adding a note stating this
feature requires Windows 10 >= 1511 update is really a Postgres business.

Please find attached a version that supports older Mingw versions and SDKs.

Regards,

Juan José Santamaría Flecha

Attachment Content-Type Size
v2-0001-command-line-colorization-on-windows.patch application/octet-stream 1.2 KB

From: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-18 22:39:39
Message-ID: CANtu0oj2z_t9d5SrTLqgZ_mOoiiAheTFp3spP7urUFiuK90=uA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello everyone.

> Please find attached a version that supports older Mingw versions and SDKs.

I have checked the patch source code and it seems to be working. But a
few moments I want to mention:

I think it is not good idea to mix the logic of detecting the fact of
TTY with enabling of the VT100 mode. Yeah, it seems to be correct for
current case but a little confusing.
Maybe is it better to detect terminal using *isatty* and later call
*enable_vt_mode*?

Also, it seems like if GetConsoleMode returns
ENABLE_VIRTUAL_TERMINAL_PROCESSING flag already set - we could skip
SetConsoleMode call (not a big deal of course).

Thanks,
Michail.


From: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-18 23:01:38
Message-ID: CANtu0og9jXgwBS0c1jZTzvE2_D3KGtkMLY_4XVMgvZUBw-mkTA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

P.S.

Also, should we enable vt100 mode in case of PG_COLOR=always? I think yes.


From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-19 16:16:32
Message-ID: CAC+AXB3cTZKR8ry-T6-ui0qLMij+K_auxO9Lq9dHy1DBj+HDHQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Feb 18, 2020 at 11:39 PM Michail Nikolaev <
michail(dot)nikolaev(at)gmail(dot)com> wrote:

>
> I have checked the patch source code and it seems to be working. But a
> few moments I want to mention:
>

Thanks for looking into this.

> I think it is not good idea to mix the logic of detecting the fact of
> TTY with enabling of the VT100 mode. Yeah, it seems to be correct for
> current case but a little confusing.
> Maybe is it better to detect terminal using *isatty* and later call
> *enable_vt_mode*?
>

Most of what enable_vt_mode() does is actually detecting the terminal, but
I can see why that is confusing without better comments.

> Also, it seems like if GetConsoleMode returns
> ENABLE_VIRTUAL_TERMINAL_PROCESSING flag already set - we could skip
> SetConsoleMode call (not a big deal of course).
>

Agreed.

The patch about making color by default [1] introduces the
function terminal_supports_color(), that I think is relevant for this
issue. Please find attached a new version based on that idea.

Also, adding Peter to weight on this approach.

[1] https://commitfest.postgresql.org/27/2406/

Regards,

Juan José Santamaría Flecha

Attachment Content-Type Size
v3-0001-command-line-colorization-on-windows.patch application/octet-stream 2.3 KB

From: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-22 20:08:45
Message-ID: CANtu0oic8bkGZ6uSA6NPp=dKCwpBd22yk2tJmUKCX5PVVAzMDA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello.

> The patch about making color by default [1] introduces the function terminal_supports_color(), that I think is relevant for this issue. Please find attached a new version based on that idea.

I am not sure it is good idea to mix both patches because it adds some
confusion and makes it harder to merge each.
Maybe is it better to update current patch the way to reuse some
function later in [1]?

Also, regarding comment
> It is disabled by default, so it must be enabled to use color outpout.

It is not true for new terminal, for example. Maybe it is better to
rephrase it to something like: "Check if TV100 support if enabled and
attempt to enable if not".

[1] https://www.postgresql.org/message-id/flat/bbdcce43-bd2e-5599-641b-9b44b9e0add4(at)2ndquadrant(dot)com


From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-24 17:56:05
Message-ID: CAC+AXB0LSzuE7veUrw0-N=cxKEV_hfZTT_RaPMfMeRY3co-RQA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Sat, Feb 22, 2020 at 9:09 PM Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
wrote:

>
> I am not sure it is good idea to mix both patches because it adds some
> confusion and makes it harder to merge each.
> Maybe is it better to update current patch the way to reuse some
> function later in [1]?
>

The patch was originaly reported for Windows, but looking into Peter's
patch, I think this issue affects other systems unless we use stricter
logic to detect a colorable terminal when using the "auto" option.
Probably, the way to go is leaving this patch as WIN32 only and thinking
about a future patch.

> Also, regarding comment
> > It is disabled by default, so it must be enabled to use color outpout.
>
> It is not true for new terminal, for example. Maybe it is better to
> rephrase it to something like: "Check if TV100 support if enabled and
> attempt to enable if not".
>

The logic I have seen on new terminals is that VT100 is supported but
disabled. Would you find clearer? "Attempt to enable VT100 sequence
processing. If it is not possible consider it as unsupported."

Please find attached a patch addressing these comments.

Regards,

Juan José Santamaría Flecha

Attachment Content-Type Size
v4-0001-command-line-colorization-on-windows.patch application/octet-stream 1.6 KB

From: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-26 10:48:09
Message-ID: CANtu0oit74eHhWsM_bLqi2NCD=OJu4bkTEfzSg0mcBaQisk5Xw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello.

Looks totally fine to me now.

So, I need to mark it as "ready to commiter", right?


From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-02-26 10:58:50
Message-ID: CAC+AXB0VCHV7+qeSJZPMb3wGxP-zP-WCcSjPyaGF23gV9s=waw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Wed, Feb 26, 2020 at 11:48 AM Michail Nikolaev <
michail(dot)nikolaev(at)gmail(dot)com> wrote:

>
> Looks totally fine to me now.
>
> So, I need to mark it as "ready to commiter", right?
>

Yes, that's right. Thanks for reviewing it.

Regards


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-03-02 06:48:42
Message-ID: 20200302064842.GE32059@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Mon, Feb 24, 2020 at 06:56:05PM +0100, Juan José Santamaría Flecha wrote:
> The patch was originaly reported for Windows, but looking into Peter's
> patch, I think this issue affects other systems unless we use stricter
> logic to detect a colorable terminal when using the "auto" option.
> Probably, the way to go is leaving this patch as WIN32 only and thinking
> about a future patch.

It is better to not mix issues. You can actually bump on similar
coloring issues depending on your configuration, with OSX or even
Linux.

> The logic I have seen on new terminals is that VT100 is supported but
> disabled. Would you find clearer? "Attempt to enable VT100 sequence
> processing. If it is not possible consider it as unsupported."
>
> Please find attached a patch addressing these comments.

I was reading the thread for the first time, and got surprised first
with the argument about "always" which gives the possibility to print
incorrect characters even if the environment does not allow coloring.
However, after looking at logging.c, the answer is pretty clear what
always is about as it enforces colorization, so this patch looks
correct to me.

On top of that, and that's a separate issue, I have noticed that we
have exactly zero documentation about PG_COLORS (the plural flavor,
not the singular), but we have code for it in common/logging.c..

Anyway, committed down to 12, after tweaking a few things.
--
Michael


From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16108: Colorization to the output of command-line has unproperly behaviors at Windows platform
Date: 2020-03-02 09:01:42
Message-ID: CAC+AXB3_PDKYLnNjebsK1NT9wX1TQpa_eB_w4vUOi2S7MvsrfA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Mon, Mar 2, 2020 at 7:48 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:

>
> On top of that, and that's a separate issue, I have noticed that we
> have exactly zero documentation about PG_COLORS (the plural flavor,
> not the singular), but we have code for it in common/logging.c..
>

Yeah, there is nothing about it prior to [1]. So, this conversation will
have to be carried over there.

> Anyway, committed down to 12, after tweaking a few things.
>

Thank you.

[1]
https://www.postgresql.org/message-id/bbdcce43-bd2e-5599-641b-9b44b9e0add4@2ndquadrant.com

Regards,

Juan José Santamaría Flecha