public class ConsoleConfigureAction implements Action<OutputEventRenderer> {
private static boolean useAnsiOutput = "true".equalsIgnoreCase(System.getProperty("org.gradle.ansi", "false"));
public void execute(OutputEventRenderer renderer) {
ConsoleMetaData consoleMetaData = null;
if(useAnsiOutput) {
consoleMetaData = new FallbackConsoleMetaData();
} else {
ConsoleDetector consoleDetector = NativeServices.getInstance().get(ConsoleDetector.class);
consoleMetaData = consoleDetector.getConsole();
}
if (consoleMetaData == null) {
return;
}
boolean stdOutIsTerminal = consoleMetaData.isStdOut();
boolean stdErrIsTerminal = consoleMetaData.isStdErr();
if (stdOutIsTerminal) {
OutputStream originalStdOut = renderer.getOriginalStdOut();
PrintStream outStr = new PrintStream(useAnsiOutput ? originalStdOut : org.fusesource.jansi.AnsiConsole.wrapOutputStream(originalStdOut));
Console console = new AnsiConsole(outStr, outStr, renderer.getColourMap(), useAnsiOutput);
renderer.addConsole(console, true, stdErrIsTerminal, consoleMetaData);