I’m experiencing a weird problem with printing 24-bit colors in the Git Bash terminal using Node.js. When I run a simple JavaScript script that uses ANSI codes to print 24-bit (true color) text, only the basic 16 colors are displayed. However, when I run a direct ANSI command in the Git Bash terminal, the 24-bit colors display perfectly. This problem doesn’t happen with other terminals(windows cmd in my case).
It seems that the issue might be related specifically to Node.js in Git Bash. Has anyone else encountered this, or is there a known workaround to get Node to display 24-bit colors in Git Bash?
Expanding on tests and context:
my node version is v20.10.0, my git version is 2.47.0.windows.2 and my OS is Windows.
This is a simple JavaScript code to test the colors:
console.log("x1b[38;2;255;0;0m█x1b[38;2;200;0;0m█")
process.stdout.write("x1b[38;2;255;0;0m█x1b[38;2;200;0;0m█")
process.stdout.write('x1b[0mn');
Executing through Git Bash it display only one basic color (console.log
and process.stdout.write
present the same result):
bash doesn’t display the full colors
If I execute the same command in a Windows cmd terminal it gives the correct colors:
cmd display the full colors
However! If I do the equivalent code directly into bash terminal, it gives the expected result:
bash displays the colors with direct code
These test imply that the code works on other terminals and that bash is capable of displaying the correct colors.
I feel that it has to have an obvious reason. But, I wasn’t able to find any mention to this specific problem.