Skip to content

Commit

Permalink
Merge pull request #59 from KyoriPowered/feat/j22-terminal-check
Browse files Browse the repository at this point in the history
feat: Handle J22 logic for detecting if a console is interactive
  • Loading branch information
zml2008 authored Dec 10, 2024
2 parents bcd29e1 + 4c71ef6 commit cdb525c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<suppressions>
<!-- no javadoc on test classes -->
<suppress files="src[\\/](test|jmh)[\\/]java[\\/].*" checks="(FilteringWriteTag|JavadocPackage|MissingJavadoc.*)"/>
<suppress files="src[\\/](test|jmh|main)[\\/]java[\d]+[\\/].*" checks="JavadocPackage"/>
</suppressions>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ eclipse {
sourceSets {
main {
multirelease {
alternateVersions(9)
alternateVersions(9, 22)
moduleName "net.kyori.ansi"
requireAllPackagesExported()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/kyori/ansi/ColorLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public enum ColorLevel {
}
} else if (WT_SESSION != null) {
return ColorLevel.TRUE_COLOR; // Windows Terminal
} else if (System.console() != null) {
} else if (SystemConsole.isTerminal()) {
if (JAnsiColorLevel.isAvailable()) {
return JAnsiColorLevel.computeFromJAnsi();
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/net/kyori/ansi/SystemConsole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of ansi, licensed under the MIT License.
*
* Copyright (c) 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.ansi;

// multi-release stub, see J22 version
final class SystemConsole {
private SystemConsole() {
}

static boolean isTerminal() {
return System.console() != null;
}
}
33 changes: 33 additions & 0 deletions src/main/java22/net/kyori/ansi/SystemConsole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of ansi, licensed under the MIT License.
*
* Copyright (c) 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.ansi;

final class SystemConsole {
private SystemConsole() {
}

static boolean isTerminal() {
return System.console() != null && System.console().isTerminal();
}
}

0 comments on commit cdb525c

Please sign in to comment.