File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,11 @@ public class TextFormatter {
20
20
/**
21
21
* When set to {@code false}, no formatting will be applied to text. Raw text will be generated without any
22
22
* 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()
23
26
*/
24
- public static boolean enableSequences = !TextFormatter .getNoColorEnvironment ();
27
+ public static boolean enableSequences = !TextFormatter .isColorDisabledEnv ();
25
28
26
29
/**
27
30
* 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)
389
392
* <a href="https://no-color.org/">NO_COLOR.org</a>
390
393
* @return {@code true} if the terminal supports color
391
394
*/
392
- public static boolean getNoColorEnvironment () {
395
+ public static boolean isColorDisabledEnv () {
393
396
return System .getenv ("NO_COLOR" ) != null ;
394
397
}
395
398
Original file line number Diff line number Diff line change @@ -107,4 +107,13 @@ public void testEmpty() {
107
107
public void testStartWithDefault () {
108
108
check (SimpleColor .BRIGHT_WHITE + "test" , TextFormatter .of ("test" , SimpleColor .BRIGHT_WHITE ).toString ());
109
109
}
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
+ }
110
119
}
You can’t perform that action at this time.
0 commit comments