Skip to content

Commit

Permalink
improve colorlevel detection
Browse files Browse the repository at this point in the history
we now treat every interactive terminal as supporting at least 16 colors and make the (COLOR)TERM checks more broad

ref: PaperMC/Paper#11637

Co-authored-by: Riley Park <[email protected]>
  • Loading branch information
MiniDigger and kashike committed Nov 21, 2024
1 parent a4d84dd commit 1a1acac
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/java/net/kyori/ansi/ColorLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,25 @@ public enum ColorLevel {

// TODO
// https://github.com/termstandard/colors
if (COLORTERM != null && (COLORTERM.equals("truecolor") || COLORTERM.equals("24bit"))) {
return ColorLevel.TRUE_COLOR;
} else if (TERM != null && TERM.contains("truecolor")) {
return ColorLevel.TRUE_COLOR;
} else if (TERM != null && TERM.contains("256color")) {
return ColorLevel.INDEXED_256;
} else if (TERM == null) {
if (WT_SESSION != null) {
return ColorLevel.TRUE_COLOR; // Windows Terminal
} else if (System.console() != null && JAnsiColorLevel.isAvailable()) {
if (COLORTERM != null) {
if (COLORTERM.contains("truecolor") || COLORTERM.contains("24bit")) {
return ColorLevel.TRUE_COLOR;
}
} else if (TERM != null) {
if (TERM.contains("truecolor") || TERM.contains("-direct")) {
return ColorLevel.TRUE_COLOR;
} else if (TERM.contains("-256color")) {
return ColorLevel.INDEXED_256;
}
} else if (WT_SESSION != null) {
return ColorLevel.TRUE_COLOR; // Windows Terminal
} else if (System.console() != null) {
if (JAnsiColorLevel.isAvailable()) {
return JAnsiColorLevel.computeFromJAnsi();
} else {
return ColorLevel.NONE; // This isn't a terminal at all
}
return ColorLevel.INDEXED_16; // we have to assume that every interactive terminal supports at least 16 colors
} else {
return ColorLevel.NONE; // This isn't a terminal at all
}

// Fallback, unknown type of terminal
Expand Down

0 comments on commit 1a1acac

Please sign in to comment.