From a39d6f84e106a80bd63d8ec89e86d65c2c70aede Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 29 Feb 2016 10:21:13 +0000 Subject: 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 --- .../devtools/build/lib/runtime/ExperimentalEventHandler.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/main') 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 5d4918e268..3d7b82fe39 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.events.EventKind; 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 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler { 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 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler { private final AnsiTerminal terminal; private int lineCount; - private int currentLineLength; LineCountingAnsiTerminalWriter(AnsiTerminal terminal) { this.terminal = terminal; @@ -208,7 +209,6 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler { @Override public AnsiTerminalWriter append(String text) throws IOException { terminal.writeString(text); - currentLineLength += text.length(); return this; } @@ -216,11 +216,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler { 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; } -- cgit v1.2.3