ExperimentalEventHandler: break lines explicitly
In order to correctly erase the current progress bar, we
need to know how many lines it is long. Instead of trying
to compute it, enforce explicit breaks shorter than the terminal
width.
--
Change-Id: Ifac16b351e1390f553d0ceac2b647b1178b58d0b
Reviewed-on: https://bazel-review.googlesource.com/#/c/3024
MOS_MIGRATED_REVID=115829390
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
index 5d4918e..3d7b82f 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.pkgcache.LoadingPhaseCompleteEvent;
import com.google.devtools.build.lib.util.io.AnsiTerminal;
import com.google.devtools.build.lib.util.io.AnsiTerminalWriter;
+import com.google.devtools.build.lib.util.io.LineWrappingAnsiTerminalWriter;
import com.google.devtools.build.lib.util.io.OutErr;
import java.io.IOException;
@@ -189,7 +190,8 @@
private void addProgressBar() throws IOException {
LineCountingAnsiTerminalWriter terminalWriter = new LineCountingAnsiTerminalWriter(terminal);
- stateTracker.writeProgressBar(terminalWriter);
+ stateTracker.writeProgressBar(
+ new LineWrappingAnsiTerminalWriter(terminalWriter, terminalWidth - 1));
terminalWriter.newline();
numLinesProgressBar = terminalWriter.getWrittenLines();
}
@@ -198,7 +200,6 @@
private final AnsiTerminal terminal;
private int lineCount;
- private int currentLineLength;
LineCountingAnsiTerminalWriter(AnsiTerminal terminal) {
this.terminal = terminal;
@@ -208,7 +209,6 @@
@Override
public AnsiTerminalWriter append(String text) throws IOException {
terminal.writeString(text);
- currentLineLength += text.length();
return this;
}
@@ -216,11 +216,7 @@
public AnsiTerminalWriter newline() throws IOException {
terminal.cr();
terminal.writeString("\n");
- // Besides the line ended by the newline() command, a line-shift can also happen
- // by a string longer than the terminal width being wrapped around; account for
- // this as well.
- lineCount += 1 + currentLineLength / terminalWidth;
- currentLineLength = 0;
+ lineCount++;
return this;
}