Skip to content

Commit

Permalink
Only show the progress bar after printing stdout/stderr if the printi…
Browse files Browse the repository at this point in the history
…ng cleared the progress bar.

I'm not sure how to add a test for this because the fancy terminal overwriting the ui does isn't really compatible with our test infrastructure for assertions on blaze output. Will keep on trying, but wanted to fix the bug first.

PiperOrigin-RevId: 344144890
  • Loading branch information
janakdr authored and copybara-github committed Nov 24, 2020
1 parent 8811e27 commit 6ce39b4
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ private void handleLocked(Event event, @Nullable byte[] stdout, @Nullable byte[]
stream.write(event.getMessageBytes());
stream.flush();
} else {
writeToStream(stream, event.getKind(), event.getMessageBytes());
if (showProgress && cursorControl) {
boolean clearedProgress =
writeToStream(stream, event.getKind(), event.getMessageBytes());
if (clearedProgress && showProgress && cursorControl) {
addProgressBar();
}
terminal.flush();
Expand Down Expand Up @@ -452,14 +453,14 @@ public void handle(Event event) {
handleInternal(event);
}

private void writeToStream(OutputStream stream, EventKind eventKind, byte[] message)
private boolean writeToStream(OutputStream stream, EventKind eventKind, byte[] message)
throws IOException {
int eolIndex = Bytes.lastIndexOf(message, (byte) '\n');
ByteArrayOutputStream outLineBuffer =
eventKind == EventKind.STDOUT ? stdoutLineBuffer : stderrLineBuffer;
if (eolIndex < 0) {
outLineBuffer.write(message);
return;
return false;
}

clearProgressBar();
Expand All @@ -473,6 +474,7 @@ private void writeToStream(OutputStream stream, EventKind eventKind, byte[] mess
stream.flush();

outLineBuffer.write(message, eolIndex + 1, message.length - eolIndex - 1);
return true;
}

private void setEventKindColor(EventKind kind) throws IOException {
Expand Down

0 comments on commit 6ce39b4

Please sign in to comment.