Skip to content

Commit b36fe2c

Browse files
committed
Cache outcome of checking to see if host supports ANSI output
Closes gh-4510
1 parent 8dc3b71 commit b36fe2c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/ansi/AnsiOutput.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public abstract class AnsiOutput {
3030

3131
private static Enabled enabled = Enabled.DETECT;
3232

33+
private static Boolean ansiCapable;
34+
3335
private static final String OPERATING_SYSTEM_NAME = System.getProperty("os.name")
3436
.toLowerCase();
3537

@@ -108,12 +110,19 @@ private static void buildDisabled(StringBuilder sb, Object[] elements) {
108110

109111
private static boolean isEnabled() {
110112
if (enabled == Enabled.DETECT) {
111-
return detectIfEnabled();
113+
return detectIfAnsiCapable();
112114
}
113115
return enabled == Enabled.ALWAYS;
114116
}
115117

116-
private static boolean detectIfEnabled() {
118+
private static boolean detectIfAnsiCapable() {
119+
if (ansiCapable == null) {
120+
ansiCapable = doDetectIfAnsiCapable();
121+
}
122+
return ansiCapable;
123+
}
124+
125+
private static boolean doDetectIfAnsiCapable() {
117126
try {
118127
if (System.console() == null) {
119128
return false;

0 commit comments

Comments
 (0)