Search in sources :

Example 1 with Console

use of org.gradle.internal.logging.console.Console in project gradle by gradle.

the class ConsoleConfigureAction method execute.

public void execute(OutputEventRenderer renderer, ConsoleOutput consoleOutput) {
    if (consoleOutput == ConsoleOutput.Plain) {
        return;
    }
    ConsoleDetector consoleDetector = NativeServices.getInstance().get(ConsoleDetector.class);
    ConsoleMetaData consoleMetaData = consoleDetector.getConsole();
    boolean force = false;
    if (consoleMetaData == null) {
        if (consoleOutput == ConsoleOutput.Auto) {
            return;
        }
        assert consoleOutput == ConsoleOutput.Rich;
        consoleMetaData = new FallbackConsoleMetaData();
        force = true;
    }
    boolean stdOutIsTerminal = consoleMetaData.isStdOut();
    boolean stdErrIsTerminal = consoleMetaData.isStdErr();
    int numWorkersToDisplay = ConsoleLayoutCalculator.calculateNumWorkersForConsoleDisplay(consoleMetaData);
    if (stdOutIsTerminal) {
        OutputStream originalStdOut = renderer.getOriginalStdOut();
        OutputStreamWriter outStr = new OutputStreamWriter(force ? originalStdOut : AnsiConsoleUtil.wrapOutputStream(originalStdOut));
        Console console = new AnsiConsole(outStr, outStr, renderer.getColourMap(), consoleMetaData, numWorkersToDisplay, force);
        renderer.addConsole(console, true, stdErrIsTerminal, consoleMetaData);
    } else if (stdErrIsTerminal) {
        // Only stderr is connected to a terminal
        OutputStream originalStdErr = renderer.getOriginalStdErr();
        OutputStreamWriter errStr = new OutputStreamWriter(force ? originalStdErr : AnsiConsoleUtil.wrapOutputStream(originalStdErr));
        Console console = new AnsiConsole(errStr, errStr, renderer.getColourMap(), consoleMetaData, numWorkersToDisplay, force);
        renderer.addConsole(console, false, true, consoleMetaData);
    }
}
Also used : FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleDetector(org.gradle.internal.nativeintegration.console.ConsoleDetector) OutputStream(java.io.OutputStream) Console(org.gradle.internal.logging.console.Console) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleMetaData(org.gradle.internal.nativeintegration.console.ConsoleMetaData) OutputStreamWriter(java.io.OutputStreamWriter) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole)

Example 2 with Console

use of org.gradle.internal.logging.console.Console in project gradle by gradle.

the class OutputEventRenderer method attachAnsiConsole.

public void attachAnsiConsole(OutputStream outputStream) {
    synchronized (lock) {
        ConsoleMetaData consoleMetaData = new FallbackConsoleMetaData();
        OutputStreamWriter writer = new OutputStreamWriter(outputStream);
        int numWorkersToDisplay = ConsoleLayoutCalculator.calculateNumWorkersForConsoleDisplay(consoleMetaData);
        Console console = new AnsiConsole(writer, writer, colourMap, consoleMetaData, numWorkersToDisplay, true);
        addConsole(console, true, true, consoleMetaData);
    }
}
Also used : FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) Console(org.gradle.internal.logging.console.Console) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleMetaData(org.gradle.internal.nativeintegration.console.ConsoleMetaData) OutputStreamWriter(java.io.OutputStreamWriter) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole)

Example 3 with Console

use of org.gradle.internal.logging.console.Console in project gradle by gradle.

the class ConsoleConfigureAction method configureRichConsole.

private static void configureRichConsole(OutputEventRenderer renderer, ConsoleMetaData consoleMetaData, boolean force, boolean verbose) {
    consoleMetaData = consoleMetaData == null ? FallbackConsoleMetaData.INSTANCE : consoleMetaData;
    if (consoleMetaData.isStdOut()) {
        OutputStream originalStdOut = renderer.getOriginalStdOut();
        OutputStreamWriter outStr = new OutputStreamWriter(force ? originalStdOut : AnsiConsoleUtil.wrapOutputStream(originalStdOut));
        Console console = new AnsiConsole(outStr, outStr, renderer.getColourMap(), consoleMetaData, force);
        renderer.addRichConsole(console, true, consoleMetaData.isStdErr(), consoleMetaData, verbose);
    } else if (consoleMetaData.isStdErr()) {
        // Only stderr is connected to a terminal
        OutputStream originalStdErr = renderer.getOriginalStdErr();
        OutputStreamWriter errStr = new OutputStreamWriter(force ? originalStdErr : AnsiConsoleUtil.wrapOutputStream(originalStdErr));
        Console console = new AnsiConsole(errStr, errStr, renderer.getColourMap(), consoleMetaData, force);
        renderer.addRichConsole(console, false, true, consoleMetaData, verbose);
    }
}
Also used : OutputStream(java.io.OutputStream) Console(org.gradle.internal.logging.console.Console) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) OutputStreamWriter(java.io.OutputStreamWriter) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole)

Example 4 with Console

use of org.gradle.internal.logging.console.Console in project gradle by gradle.

the class OutputEventRenderer method attachConsole.

@Override
public void attachConsole(OutputStream outputStream, ConsoleOutput consoleOutput) {
    synchronized (lock) {
        if (consoleOutput == ConsoleOutput.Plain) {
            addPlainConsole(new StreamBackedStandardOutputListener(outputStream));
        } else {
            ConsoleMetaData consoleMetaData = FallbackConsoleMetaData.INSTANCE;
            OutputStreamWriter writer = new OutputStreamWriter(outputStream);
            Console console = new AnsiConsole(writer, writer, getColourMap(), consoleMetaData, true);
            addRichConsole(console, true, true, consoleMetaData, consoleOutput == ConsoleOutput.Verbose);
        }
    }
}
Also used : Console(org.gradle.internal.logging.console.Console) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleMetaData(org.gradle.internal.nativeintegration.console.ConsoleMetaData) OutputStreamWriter(java.io.OutputStreamWriter) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) StreamBackedStandardOutputListener(org.gradle.internal.logging.text.StreamBackedStandardOutputListener)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)4 AnsiConsole (org.gradle.internal.logging.console.AnsiConsole)4 Console (org.gradle.internal.logging.console.Console)4 ConsoleMetaData (org.gradle.internal.nativeintegration.console.ConsoleMetaData)3 FallbackConsoleMetaData (org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData)3 OutputStream (java.io.OutputStream)2 StreamBackedStandardOutputListener (org.gradle.internal.logging.text.StreamBackedStandardOutputListener)1 ConsoleDetector (org.gradle.internal.nativeintegration.console.ConsoleDetector)1