Skip to content

Commit 13b238e

Browse files
committed
add test for disabled formatting
1 parent 53f81f0 commit 13b238e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/textFormatter/TextFormatter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public class TextFormatter {
2020
/**
2121
* When set to {@code false}, no formatting will be applied to text. Raw text will be generated without any
2222
* color or formatting.
23+
* <p>
24+
* This will be set to {@code false} if the environment variable {@code NO_COLOR} is set.
25+
* @see #isColorDisabledEnv()
2326
*/
24-
public static boolean enableSequences = !TextFormatter.getNoColorEnvironment();
27+
public static boolean enableSequences = !TextFormatter.isColorDisabledEnv();
2528

2629
/**
2730
* The default color that should be used when no foreground color is specified (if {@link #startWithDefaultColorIfNotDefined}
@@ -389,7 +392,7 @@ else if (TextFormatter.startWithDefaultColorIfNotDefined && this.parent == null)
389392
* <a href="https://no-color.org/">NO_COLOR.org</a>
390393
* @return {@code true} if the terminal supports color
391394
*/
392-
public static boolean getNoColorEnvironment() {
395+
public static boolean isColorDisabledEnv() {
393396
return System.getenv("NO_COLOR") != null;
394397
}
395398

src/test/java/TextFormatterTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@ public void testEmpty() {
107107
public void testStartWithDefault() {
108108
check(SimpleColor.BRIGHT_WHITE + "test", TextFormatter.of("test", SimpleColor.BRIGHT_WHITE).toString());
109109
}
110+
111+
@Test
112+
public void testDisabledFormatting() {
113+
TextFormatter.enableSequences = false;
114+
var formatter = TextFormatter.of("red text here", SimpleColor.RED);
115+
116+
check("red text here", formatter.toString());
117+
TextFormatter.enableSequences = true;
118+
}
110119
}

0 commit comments

Comments
 (0)