Skip to content

Commit 1ff3292

Browse files
More closely match the logic from the supports_color crate
1 parent 2034f5b commit 1ff3292

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/java/com/opencastsoftware/yvette/handlers/graphical/TerminalSupport.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,25 @@ public static boolean supportsUnicode(Appendable output) {
110110
}
111111

112112
static boolean checkAnsiColourSupport(String varName) {
113-
return envVarIn(varName,
114-
"screen", "xterm", "vt100",
115-
"vt220", "rxvt", "color",
116-
"ansi", "cygwin", "linux");
113+
return envVarMatches(varName,
114+
t -> t.startsWith("screen")
115+
|| t.startsWith("xterm")
116+
|| t.startsWith("vt100")
117+
|| t.startsWith("vt220")
118+
|| t.startsWith("rxvt")
119+
|| t.contains("color")
120+
|| t.contains("ansi")
121+
|| t.contains("cygwin")
122+
|| t.contains("linux"));
117123
}
118124

119125
static boolean check256ColourSupport(String varName) {
120126
return envVarMatches(varName, t -> t.endsWith("256") || t.endsWith("256color"));
121127
}
122128

129+
/*
130+
* A port of the logic from https://docs.rs/supports-color/2.0.0/supports_color/
131+
*/
123132
public static ColourSupport colourSupport(Appendable output) {
124133
if (envVarNotEquals("NO_COLOR", "") || envVarEquals("TERM", "dumb") || !isAtty(output)) {
125134
return ColourSupport.NONE;

0 commit comments

Comments
 (0)