diff --git a/.circleci/config.yml b/.circleci/config.yml index ef61d0e..141b6f4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ executors: - image: cimg/base:stable environment: JVM_OPTS: -Xmx4096m - TERM: dumb + TERM: xterm resource_class: large commands: diff --git a/README.md b/README.md index b120985..48520e2 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,13 @@ apply(plugin = "io.github.joselion.pretty-jupiter") ``` -## Extension properties +### Plain output + +You may need the output to be plain (colorless and with text-based icons) for example, for logging to a file or for a CI environment. This is possible by setting the environment variable `TERM=dumb` before running your test command. + +> Keep in mind that using `--console=plain` will not work at the moment as checking for that flag is not supported by Gradle (check [this gradle issue](https://github.com/gradle/gradle/issues/11133) for details). + +### Extension properties The plugin can be customized adding a `prettyJupiter` closure to your `build.gradle` file and changing the following properties: diff --git a/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Icons.groovy b/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Icons.groovy index f78c51c..d0e91b8 100644 --- a/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Icons.groovy +++ b/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Icons.groovy @@ -1,9 +1,9 @@ package io.github.joselion.prettyjupiter.helpers enum Icons { - SUCCESS(Utils.coloredText(Colors.GREEN, '✔')), - FAILURE(Utils.coloredText(Colors.RED, '✖')), - SKIPPED('⚠️ ') + SUCCESS(Utils.isTermDumb() ? '√' : Utils.coloredText(Colors.GREEN, '✔')), + FAILURE(Utils.isTermDumb() ? 'X' : Utils.coloredText(Colors.RED, '✖')), + SKIPPED(Utils.isTermDumb() ? '!' : '⚠️ ') private final String icon diff --git a/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Utils.groovy b/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Utils.groovy index 4bf3995..7996d8e 100644 --- a/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Utils.groovy +++ b/src/main/groovy/io/github/joselion/prettyjupiter/helpers/Utils.groovy @@ -23,7 +23,9 @@ class Utils { static String coloredText(Colors color, String text) { final String colorCode = color.getCode() - return "${ESC}[${colorCode}m${text}${ESC}[0m" + return !Utils.isTermDumb() + ? "${ESC}[${colorCode}m${text}${ESC}[0m" + : text } static String limitedText(String text, Integer maxLines) { @@ -57,4 +59,10 @@ class Utils { return text.replace("$ESC", '') .replaceAll(/\[\d*m/, '') } + + static boolean isTermDumb() { + final String term = System.getenv('TERM') ?: '' + + return term.equalsIgnoreCase('dumb') + } }