2121
2222import org .fusesource .jansi .Ansi ;
2323import org .fusesource .jansi .AnsiConsole ;
24+ import org .fusesource .jansi .AnsiMode ;
2425
2526/**
2627 * 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()
8182 // hook can only set when JANSI is true
8283 if ( shutdownHook != null )
8384 {
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
8686 {
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
9592 }
9693 }
9794 }
@@ -113,7 +110,19 @@ public static void setColorEnabled( boolean flag )
113110 {
114111 if ( JANSI )
115112 {
113+ AnsiConsole .out ().setMode ( flag ? AnsiMode .Force : AnsiMode .Strip );
116114 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+ }
117126 }
118127 }
119128
@@ -194,7 +203,10 @@ public void run()
194203 {
195204 synchronized ( STARTUP_SHUTDOWN_MONITOR )
196205 {
197- doSystemUninstall ();
206+ while ( AnsiConsole .isInstalled () )
207+ {
208+ doSystemUninstall ();
209+ }
198210 }
199211 }
200212 };
0 commit comments