Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve colorlevel detection #57

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/main/java/net/kyori/ansi/ColorLevel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of ansi, licensed under the MIT License.
*
* Copyright (c) 2021-2023 KyoriPowered
* Copyright (c) 2021-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down 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