21
21
22
22
import org .fusesource .jansi .Ansi ;
23
23
import org .fusesource .jansi .AnsiConsole ;
24
+ import org .fusesource .jansi .AnsiMode ;
24
25
25
26
/**
26
27
* Colored message utils, to manage colors consistently across plugins (only if Maven version is at least 3.5.0).
@@ -81,17 +82,13 @@ public static void systemUninstall()
81
82
// hook can only set when JANSI is true
82
83
if ( shutdownHook != null )
83
84
{
84
- // if out and system_out are same instance again, ansi is assumed to be uninstalled
85
- if ( AnsiConsole .out == AnsiConsole .system_out )
85
+ try
86
86
{
87
- try
88
- {
89
- Runtime .getRuntime ().removeShutdownHook ( shutdownHook );
90
- }
91
- catch ( IllegalStateException ex )
92
- {
93
- // ignore - VM is already shutting down
94
- }
87
+ Runtime .getRuntime ().removeShutdownHook ( shutdownHook );
88
+ }
89
+ catch ( IllegalStateException ex )
90
+ {
91
+ // ignore - VM is already shutting down
95
92
}
96
93
}
97
94
}
@@ -113,7 +110,19 @@ public static void setColorEnabled( boolean flag )
113
110
{
114
111
if ( JANSI )
115
112
{
113
+ AnsiConsole .out ().setMode ( flag ? AnsiMode .Force : AnsiMode .Strip );
116
114
Ansi .setEnabled ( flag );
115
+ System .setProperty ( AnsiConsole .JANSI_MODE ,
116
+ flag ? AnsiConsole .JANSI_MODE_FORCE : AnsiConsole .JANSI_MODE_STRIP );
117
+ boolean installed = AnsiConsole .isInstalled ();
118
+ while ( AnsiConsole .isInstalled () )
119
+ {
120
+ AnsiConsole .systemUninstall ();
121
+ }
122
+ if ( installed )
123
+ {
124
+ AnsiConsole .systemInstall ();
125
+ }
117
126
}
118
127
}
119
128
@@ -194,7 +203,10 @@ public void run()
194
203
{
195
204
synchronized ( STARTUP_SHUTDOWN_MONITOR )
196
205
{
197
- doSystemUninstall ();
206
+ while ( AnsiConsole .isInstalled () )
207
+ {
208
+ doSystemUninstall ();
209
+ }
198
210
}
199
211
}
200
212
};
0 commit comments