Skip to content

Commit e9b74a3

Browse files
committed
feat: Handle J22 logic for detecting if a console is interactive
1 parent 93ad339 commit e9b74a3

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

.checkstyle/suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<suppressions>
44
<!-- no javadoc on test classes -->
55
<suppress files="src[\\/](test|jmh)[\\/]java[\\/].*" checks="(FilteringWriteTag|JavadocPackage|MissingJavadoc.*)"/>
6+
<suppress files="src[\\/](test|jmh|main)[\\/]java[\d]+[\\/].*" checks="JavadocPackage"/>
67
</suppressions>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ eclipse {
4848
sourceSets {
4949
main {
5050
multirelease {
51-
alternateVersions(9)
51+
alternateVersions(9, 22)
5252
moduleName "net.kyori.ansi"
5353
requireAllPackagesExported()
5454
}

src/main/java/net/kyori/ansi/ColorLevel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public enum ColorLevel {
206206
}
207207
} else if (WT_SESSION != null) {
208208
return ColorLevel.TRUE_COLOR; // Windows Terminal
209-
} else if (System.console() != null) {
209+
} else if (SystemConsole.isTerminal()) {
210210
if (JAnsiColorLevel.isAvailable()) {
211211
return JAnsiColorLevel.computeFromJAnsi();
212212
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of ansi, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2024 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package net.kyori.ansi;
25+
26+
// multi-release stub, see J22 version
27+
final class SystemConsole {
28+
private SystemConsole() {
29+
}
30+
31+
static boolean isTerminal() {
32+
return System.console() != null;
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of ansi, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2024 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package net.kyori.ansi;
25+
26+
// multi-release stub, see J22 version
27+
final class SystemConsole {
28+
private SystemConsole() {
29+
}
30+
31+
static boolean isTerminal() {
32+
return System.console() != null && System.console().isTerminal();
33+
}
34+
}

0 commit comments

Comments
 (0)