diff options
author | Klaus Aehlig <aehlig@google.com> | 2016-05-20 10:44:21 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2016-05-20 14:41:43 +0000 |
commit | a4c7d25d219e8d748c18f8c49d1366fa1d683ab7 (patch) | |
tree | a3113726f02361e84a803d8acf38b2126a6e67b1 /src/main/java | |
parent | f62db46b49fb2016ca4dad300374ddbbe5ffee43 (diff) |
experimental UI: improve message shortening
When a progress message has to be shortened, as it does not fit in a
line in the progress bar, add a new first attempt: if the message the
path implicit to the label, only shorten that path within the message
(if that gets short enough, leaving a reasonable part of the path);
usually, the additional information is more useful than having a longer
part of the path present.
While there, also fix incorrect length computation in a different case
of message shortening.
--
Change-Id: Ied80e03cace1b249fc0f4e11bce41f2b4207b6ad
Reviewed-on: https://bazel-review.googlesource.com/#/c/3670
MOS_MIGRATED_REVID=122818198
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java index 080029f52b..3945efe8fa 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java @@ -214,8 +214,30 @@ class ExperimentalStateTracker { if (message.length() + postfix.length() <= desiredWidth) { return message + postfix; } + + // We have to shorten the message to fit into the line. + if (action.getOwner() != null) { if (action.getOwner().getLabel() != null) { + // First attempt is to shorten the package path string in the messge, if it occurs there + String pathString = action.getOwner().getLabel().getPackageFragment().toString(); + int pathIndex = message.indexOf(pathString); + if (pathIndex >= 0) { + String start = message.substring(0, pathIndex); + String end = message.substring(pathIndex + pathString.length()); + int pathTargetLength = desiredWidth - start.length() - end.length() - postfix.length(); + // This attempt of shortening is reasonable if what is left from the label + // is significantly longer (twice as long) as the ellipsis symbols introduced. + if (pathTargetLength >= 3 * ELLIPSIS.length()) { + String shortPath = suffix(pathString, pathTargetLength - ELLIPSIS.length()); + int slashPos = shortPath.indexOf('/'); + if (slashPos >= 0) { + return start + ELLIPSIS + shortPath.substring(slashPos) + end + postfix; + } + } + } + + // Second attempt: just take a shortened version of the label. String shortLabel = shortenedLabelString(action.getOwner().getLabel(), desiredWidth - postfix.length()); if (shortLabel.length() + postfix.length() <= desiredWidth) { @@ -223,7 +245,7 @@ class ExperimentalStateTracker { } } } - if (3 * ELLIPSIS.length() <= desiredWidth) { + if (3 * ELLIPSIS.length() + postfix.length() <= desiredWidth) { message = ELLIPSIS + suffix(message, desiredWidth - ELLIPSIS.length() - postfix.length()); } return message + postfix; |