cslarsen / jp2a

Converts jpg images to ASCII
GNU General Public License v2.0
797 stars 71 forks source link

[Question] True color supports on Windows WSL2 #17

Closed Dragon1573 closed 2 years ago

Dragon1573 commented 2 years ago

Hello @cslarsen, could you please do me a favour of enable true color support on WSL2? Does Windows Terminal Preview & Microsoft Bash Launcher actually support true color?

  1. If they DOES support true color, why jp2a can't detect it?
  2. If they does NOT support true color, why they can pass the test of /d/24-bit-color.sh?

Thank you!

Environments

Situations

Windows Terminal Preview

Screenshots are folded (Click to expand) ![image](https://user-images.githubusercontent.com/49941141/161690752-3f0a9f31-36e7-4335-9c31-ed789f6b4d49.png) ![image](https://user-images.githubusercontent.com/49941141/161691196-ab137728-7ff6-429c-bbdd-c290c1cfd78f.png)

Microsoft Visual Studio Code

Screenshots are folded (Click to expand) ![image](https://user-images.githubusercontent.com/49941141/161691643-b758683e-ff3c-47ea-bc0f-6891fea193eb.png) ![image](https://user-images.githubusercontent.com/49941141/161691937-d9f03885-3e78-450f-98f1-d57196894927.png)

Microsoft Bash Launcher

I also launch bash.exe with Win + R directly.

Screenshots are folded (Click to expand) ![image](https://user-images.githubusercontent.com/49941141/161692662-d2c9288b-13bc-47da-a487-90c8ad280402.png) ![image](https://user-images.githubusercontent.com/49941141/161692938-ddf1313e-a99c-4d26-a4ac-61405cbecaed.png)
Dragon1573 commented 2 years ago

According to termstandard/colors, I also installed MobaXterm on my device. But jp2a still failed to show picture in true color.

image

Talinx commented 2 years ago
  1. jp2a detects true color by inspecting the COLORTERM environment variable. True color output is only enabled if this variable is set. Some terminals do not set this variable even if the terminal actually supports true color.

  2. I guess the test /d/24-bit-color.sh is similar to this? This script does not test in a way that is programmatically detectable. It just prints some output to the console and the user has to confirm visually if the output looks like true color.

Solution: You can force jp2a to produce true color output regardless of the terminal with --color-depth=24. This can be set as an alias in .bashrc:

alias jp2a='jp2a --color-depth=24'

However --color-depth=24 implicitly enables color output. I suggest setting COLORTERM in .bashrc instead:

export COLORTERM='truecolor'

If there is a way to programmatically detect true color support that also works with Windows Terminal or Microsoft Bash Launcher that would be great and I would add it to jp2a.

Dragon1573 commented 2 years ago
  1. jp2a detects true color by inspecting the COLORTERM environment variable. True color output is only enabled if this variable is set. Some terminals do not set this variable even if the terminal actually supports true color.

Oops?! I didn't know it before... When you mentioned this, I checked my Windows Terminal and it does NOT have this variable pre-configured.

  1. I guess the test /d/24-bit-color.sh is similar to this? This script does not test in a way that is programmatically detectable. It just prints some output to the console and the user has to confirm visually if the output looks like true color.

Now I get it. Windows Terminal DOES support True Color, but only users know it (by running the script). The terminal itself know nothing about it.

Solution: You can force jp2a to produce true color output regardless of the terminal with --color-depth=24. This can be set as an alias in .bashrc:

alias jp2a='jp2a --color-depth=24'

NO. This solution is not worked on my device. Only add arguments with --color-depth=24 make no sense to the terminal.

However --color-depth=24 implicitly enables color output. I suggest setting COLORTERM in .bashrc instead:

export COLORTERM='truecolor'

THIS SOLUTION IS WORKED! I have to add set -gx COLORTERM 'truecolor' and export COLORTERM='truecolor' to both Fish and Bash. Then no matter if I add the argument, jp2a will use true color at anytime. You can try this

prompt> echo $COLORTERM
truecolor

prompt> jp2a --fill --colors --chars='  ' 'https://th.bing.com/th/id/OIP.q8A91hpnrVv1S3RxASDJyQHaEK?w=32
0&h=180&c=7&r=0&o=5&dpr=2.25&pid=1.7'
(A beautiful peafowl is shown, picture is as follows)

image

Talinx commented 2 years ago

NO. This solution is not worked on my device. Only add arguments with --color-depth=24 make no sense to the terminal.

Sorry for the confusing wording, I meant that --color-depth=24 has to be added additionally, e.g.

jp2a --fill --colors --color-depth=24 --chars='  ' 'https://th.bing.com/th/id/OIP.q8A91hpnrVv1S3RxASDJyQHaEK?w=320&h=180&c=7&r=0&o=5&dpr=2.25&pid=1.7'
Dragon1573 commented 2 years ago

No effect of this command without COLORTERM environment variable unset. I have to set the environment variable, then jp2a will automatically turn into 24-bits mode without adding --color-depth=24 argument.

Dragon1573 commented 2 years ago

Close https://github.com/Talinx/jp2a/issues/11