git-for-windows / git

A fork of Git containing Windows-specific patches.
http://gitforwindows.org/
Other
8.28k stars 2.51k forks source link

Missed color for `CSI 2 m` with the enabled support for pseudo consoles #3823

Open AlttiRi opened 2 years ago

AlttiRi commented 2 years ago

I use

Bug

\u001B[2m does not make a text gray.

More info

Python script:

import shutil, sys

print(shutil.get_terminal_size())
sys.stdout.write("\u001B[2m"    +    "2m" + "\u001B[0m\n")
sys.stdout.write("\u001B[90m"   +   "90m" + "\u001B[0m\n")
sys.stdout.write("\u001B[1;32m" + "1;32m" + "\u001B[0m\n")
sys.stdout.flush()

With enabled option "Enable experimental support for pseudo consoles." "\u001B[2m" console color is ignored: Screenshot

Without this option (however, get_terminal_size does not work in this case): Screenshot_3

Windows Terminal: Screenshot_4


https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters

dscho commented 2 years ago

Does the same happen with Cygwin?

AlttiRi commented 2 years ago

Yes. It uses mintty 3.6.1. image

It behaves the same way as Git-Bash with enabled "support for pseudo consoles" option.

dscho commented 2 years ago

I just integrated that new MinTTY version into Git for Windows' SDK.

Could you replace (as admin) C:\Program Files\Git\usr\bin\mintty.exe with the version from the SDK and see whether that addresses your problem?

AlttiRi commented 2 years ago

Nothing changed.

So, it possibly should be addressed to MinTTY authors?

Without "Enable experimental support for pseudo consoles." option color is gray, but get_terminal_size does not work. With that option enabled the color is default one, but get_terminal_size works correctly.

dscho commented 2 years ago

So, it possibly should be addressed to MinTTY authors?

Potentially. However, I have to report that the problem does not reproduce for me (this is with MinTTY v3.6.0 and pseudo console support enabled):

image

rimrul commented 2 years ago

However, I have to report that the problem does not reproduce for me (this is with MinTTY v3.6.0 and pseudo console support enabled):

Just to make sure, are you using native python through winpty or Msys2 python?

AlttiRi commented 2 years ago

A thing made with Node.js works different that the same one made with Python. (In Git-Bash terminal)

Node.js in both cases shows the console sizes, but it has very poor colors (no 8-bit colors) and it ignores 2 too.

Python always shows proper colors, except for 2 with "pseudo consoles" option. The console size is shows only with "pseudo consoles" option.

In WT the results of Node.js and Python are the same, everything is proper.

Node.js code:

const color = (code, text) => process.stdout.write("\u001B[" + code + "m" + text + "\u001B[0m\n");
color("34", "ANSI_BLUE-34");
color("1;31", "ANSI_RED_BOLD-1;31");
console.log("COMMON-TEXT; Sizes: " + process.stdout.columns + " " + process.stdout.rows);
color("2", "TEXT-2 (should be gray)");
color("38;5;208", "8bit-ORANGE-208");
color("38;5;99", "8bit-VIOLET-99");
color("38;5;92", "8bit-VIOLET-92");
color("38;5;245", "8bit-GRAY-245");

Python code:

import shutil, sys

def color(code, text):
    sys.stdout.write("\u001B[" + code + "m" + text + "\u001B[0m\n")

sizes = shutil.get_terminal_size()
color("34", "ANSI_BLUE-34");
color("1;31", "ANSI_RED_BOLD-1;31");
print("COMMON-TEXT; Sizes:", sizes[0], sizes[1]);
color("2", "TEXT-2 (should be gray)");
color("38;5;208", "8bit-ORANGE-208");
color("38;5;99", "8bit-VIOLET-99");
color("38;5;92", "8bit-VIOLET-92");
color("38;5;245", "8bit-GRAY-245");

With "pseudo consoles": with

Without: without

Windows Terminal: wt

dscho commented 2 years ago

However, I have to report that the problem does not reproduce for me (this is with MinTTY v3.6.0 and pseudo console support enabled):

Just to make sure, are you using native python through winpty or Msys2 python?

I am running Python from the Microsoft Store, not via winpty.

A thing made with Node.js works different that the same one made with Python

You're probably calling this with node <script>.js. However, node is a shell alias to winpty node.exe. If you run it via node.exe, I bet that it works the same as Python.

rimrul commented 2 years ago

I am running Python from the Microsoft Store, not via winpty.

I think we usually create a winpty alias for python. Could the pseudo console support be influencing winptys hidden console here?

AlttiRi commented 2 years ago

Yes. node.exe fixes 8-bit color.

Without the option: image

With: image

Python 3.9.9, Node.js v18.0.0 from their sites.

Well, I can fix it with alias node='node.exe' in my ~/.bashrc file.

But should Git-Bash use winpty by default, especially with pseudo console option enabled?


BTW, winpty works different with node.exe and python.exe:

image


Also some program start to use colors in their output with this option enabled. For example, yt-dlp, ffmpeg, pip. (While the colors should work even without that option.) yt-dlp

AlttiRi commented 2 years ago

Also can I toggle Enable experimental support for pseudo consoles. option without reinstalling the program?

rimrul commented 2 years ago

Also can I toggle Enable experimental support for pseudo consoles. option without reinstalling the program?

Yes. Create /etc/git-bash.config with the content MSYS=enable_pcon to enable it, delete the file to disable it. And restart Git Bash after changing it.