ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
982 stars 34 forks source link

Does not properly detect color support in XTerm on Linux #113

Closed mikaelstaldal closed 1 year ago

mikaelstaldal commented 1 year ago

XTerm on Linux gets detected as ANSI16, even though it supports more colors than that.

ajalt commented 1 year ago

I need more information to be able to help. Mordant mostly uses environment variables for ansi detection. You TERM envvar is probably set to something like xterm, try setting it to xterm-256 or xterm-24bit.

mikaelstaldal commented 1 year ago

Yes, I realized that setting TERM=xterm-256color solved the problem, and now it gets properly detected as ANSI256.

However, XTerm has the silly behavior of setting TERM=xterm by default, even though it supports 256 colors.

Maybe it would make sense for Mordant to try to detect XTerm and deduce ANSI256 regardless of TERM setting? It has this env var that could help: XTERM_VERSION=XTerm(372) ("372" is the version)

So something like if (env("XTERM_VERSION").startsWith("XTerm")) maybe?

ajalt commented 1 year ago

That's a useful envvar. I can add a check for it, but I'd want to look at the actual version number so that we don't use new ansi codes on old versions that don't support it.

It looks like 256 color support was working in version 122 and truecolor in 331.

mikaelstaldal commented 1 year ago

That's a useful envvar. I can add a check for it, but I'd want to look at the actual version number so that we don't use new ansi codes on old versions that don't support it.

It looks like 256 color support was working in version 122 and truecolor in 331.

Yes.

ajalt commented 1 year ago

@mikaelstaldal I added the xterm version check, give the latest snapshot a try and if it works I'll make a release.

mikaelstaldal commented 1 year ago

It detects TRUECOLOR as expected. And I get color output in XTerm, so it looks good.