Skip to content

Commit

Permalink
experimentalUI: agressively buffer
Browse files Browse the repository at this point in the history
To update the progress bar, we first have to remove it and then write the
new one. For this to look smooth, the control sequence removing the old progress
bar and the characters of the new progress bar have to arrive "in one go" at the
(actual) terminal. As AnsiTerminal sends each control sequence as a separate write
to the underlying stream, we have to buffer the underlying stream. Therefore,
if the experimental UI is used, buffer that stream unconditionally until flushed,
and not by line. For the experimental UI this is save, as it flushes the stream
appropriately.

For the old UI, we keep the line buffering, as the old UI relies on an implicit flush
whenever a new-line character is written.

Change-Id: I3a914e4b93ce17c3de05df0d860cf98849c3b4a1
PiperOrigin-RevId: 161935218
  • Loading branch information
aehlig authored and laszlocsomor committed Jul 14, 2017
1 parent ecb15d3 commit 678c852
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.OptionsParsingException;
import com.google.devtools.common.options.OptionsProvider;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -428,11 +429,11 @@ private int execExclusively(
}

if (!commandAnnotation.binaryStdOut()) {
outErr = lineBufferOut(outErr);
outErr = bufferOut(outErr, eventHandlerOptions.experimentalUi);
}

if (!commandAnnotation.binaryStdErr()) {
outErr = lineBufferErr(outErr);
outErr = bufferErr(outErr, eventHandlerOptions.experimentalUi);
}

CommonCommandOptions commonOptions = options.getOptions(CommonCommandOptions.class);
Expand Down Expand Up @@ -723,13 +724,23 @@ private static void getCommandNamesToParseHelper(Command commandAnnotation,
accumulator.add(commandAnnotation.name());
}

private OutErr lineBufferOut(OutErr outErr) {
OutputStream wrappedOut = new LineBufferedOutputStream(outErr.getOutputStream());
private OutErr bufferOut(OutErr outErr, boolean fully) {
OutputStream wrappedOut;
if (fully) {
wrappedOut = new BufferedOutputStream(outErr.getOutputStream());
} else {
wrappedOut = new LineBufferedOutputStream(outErr.getOutputStream());
}
return OutErr.create(wrappedOut, outErr.getErrorStream());
}

private OutErr lineBufferErr(OutErr outErr) {
OutputStream wrappedErr = new LineBufferedOutputStream(outErr.getErrorStream());
private OutErr bufferErr(OutErr outErr, boolean fully) {
OutputStream wrappedErr;
if (fully) {
wrappedErr = new BufferedOutputStream(outErr.getErrorStream());
} else {
wrappedErr = new LineBufferedOutputStream(outErr.getErrorStream());
}
return OutErr.create(outErr.getOutputStream(), wrappedErr);
}

Expand Down Expand Up @@ -902,4 +913,4 @@ public void shutdown() {
closeSilently(logOutputStream);
logOutputStream = null;
}
}
}

0 comments on commit 678c852

Please sign in to comment.