Skip to content

Commit

Permalink
feat(output): Allow use of TERM=dumb to remove colors and use simple …
Browse files Browse the repository at this point in the history
…icons (#129)
  • Loading branch information
JoseLion authored Jan 13, 2023
1 parent 20b6d7c commit ecca925
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ executors:
- image: cimg/base:stable
environment:
JVM_OPTS: -Xmx4096m
TERM: dumb
TERM: xterm
resource_class: large

commands:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ apply(plugin = "io.github.joselion.pretty-jupiter")
```
</details>

## 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:

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
}
}

0 comments on commit ecca925

Please sign in to comment.