From 8faa39d165cb9e91d71b304977b3d8db33a48c3a Mon Sep 17 00:00:00 2001 From: Andres Almiray Date: Thu, 26 Jan 2023 19:47:33 +0100 Subject: [PATCH] feat: Enhance Ansiconsole to detect no color settings --- .../org/kordamp/gradle/util/AnsiConsole.groovy | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/util/AnsiConsole.groovy b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/util/AnsiConsole.groovy index f2d3a71ae..2b11e8272 100644 --- a/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/util/AnsiConsole.groovy +++ b/plugins/base-gradle-plugin/src/main/groovy/org/kordamp/gradle/util/AnsiConsole.groovy @@ -28,15 +28,26 @@ import org.gradle.api.logging.configuration.ConsoleOutput */ @CompileStatic class AnsiConsole implements Serializable { - private boolean plain + final boolean plain AnsiConsole(Project project) { - this(project.gradle) + this(project.gradle, '') } AnsiConsole(Gradle gradle) { + this(gradle, '') + } + + AnsiConsole(Project project, String appName) { + this(project.gradle, appName) + } + + AnsiConsole(Gradle gradle, String appName) { plain = gradle.startParameter.consoleOutput == ConsoleOutput.Plain || - 'plain'.equalsIgnoreCase(System.getProperty('org.gradle.console')) + 'plain'.equalsIgnoreCase(System.getProperty('org.gradle.console')) || + System.getenv().containsKey('NO_COLOR') || + (appName && System.getenv().containsKey(appName.toUpperCase(Locale.ENGLISH) + '_NO_COLOR')) || + System.getenv().get('TERM') == 'dumb' } String black(CharSequence s) {