Skip to content

Commit

Permalink
Accept more forced color values
Browse files Browse the repository at this point in the history
While at it, extract color values for TERM / COLORTERM to variables.
  • Loading branch information
sschuberth committed Feb 22, 2024
1 parent 412f04f commit 20cbdd4
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -4,6 +4,9 @@ import com.github.ajalt.mordant.internal.*
import com.github.ajalt.mordant.rendering.AnsiLevel
import com.github.ajalt.mordant.rendering.AnsiLevel.*

private val TERM_256COLOR_VALUES = setOf("256", "256color", "256colors")
private val COLORTERM_TRUECOLOR_VALUES = setOf("24bit", "24bits", "truecolor")

internal object TerminalDetection {
fun detectTerminal(
ansiLevel: AnsiLevel?,
Expand Down Expand Up @@ -72,9 +75,7 @@ internal object TerminalDetection {

if (isJediTerm()) return TRUECOLOR

when (getColorTerm()) {
"24bit", "24bits", "truecolor" -> return TRUECOLOR
}
if (getColorTerm() in COLORTERM_TRUECOLOR_VALUES) return TRUECOLOR

if (isCI()) {
return if (ciSupportsColor()) ANSI256 else NONE
Expand All @@ -93,8 +94,8 @@ internal object TerminalDetection {
?: (null to null)

when (level) {
"256", "256color", "256colors" -> return ANSI256
"24bit", "24bits", "direct", "truecolor" -> return TRUECOLOR
in TERM_256COLOR_VALUES -> return ANSI256
in COLORTERM_TRUECOLOR_VALUES, "direct" -> return TRUECOLOR
}


Expand Down Expand Up @@ -139,8 +140,8 @@ internal object TerminalDetection {
else -> when (getEnv("FORCE_COLOR")?.lowercase()) {
"0", "false", "none" -> NONE
"1", "", "true", "16color" -> ANSI16
"2", "256color" -> ANSI256
"3", "truecolor" -> TRUECOLOR
"2", in TERM_256COLOR_VALUES -> ANSI256
"3", in COLORTERM_TRUECOLOR_VALUES -> TRUECOLOR
else -> null
}
}
Expand Down

0 comments on commit 20cbdd4

Please sign in to comment.