Skip to content

Commit

Permalink
experimental UI: honor --curses
Browse files Browse the repository at this point in the history
Bazel can be asked to uses colors, but not to use other curses options.
In this case, the ExperimentalEventHandler cannot rely on the terminal
to ignore all curses output; hence it has to actively refrain from using
curses that move the cursor.

--
Change-Id: I026edade4366a8c5a8e56d376e8a4603f5c73b92
Reviewed-on: https://bazel-review.googlesource.com/#/c/3291
MOS_MIGRATED_REVID=119439855
  • Loading branch information
aehlig authored and lberki committed Apr 11, 2016
1 parent 63049cc commit 759bbfe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
public class ExperimentalEventHandler extends BlazeCommandEventHandler {
private static Logger LOG = Logger.getLogger(ExperimentalEventHandler.class.getName());

private final boolean cursorControl;
private final AnsiTerminal terminal;
private final boolean debugAllEvents;
private final ExperimentalStateTracker stateTracker;
Expand All @@ -54,6 +55,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
public ExperimentalEventHandler(
OutErr outErr, BlazeCommandEventHandler.Options options, Clock clock) {
super(outErr, options);
this.cursorControl = options.useCursorControl();
this.terminal = new AnsiTerminal(outErr.getErrorStream());
this.terminalWidth = (options.terminalColumns > 0 ? options.terminalColumns : 80);
this.debugAllEvents = options.experimentalUiDebugAllEvents;
Expand Down Expand Up @@ -224,6 +226,9 @@ public void resetTerminal() {
}

private void clearProgressBar() throws IOException {
if (!cursorControl) {
return;
}
for (int i = 0; i < numLinesProgressBar; i++) {
terminal.cr();
terminal.cursorUp(1);
Expand Down
13 changes: 13 additions & 0 deletions src/test/shell/integration/experimental_ui_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ function test_basic_progress() {
expect_log $'\x1b\[1A\x1b\[K'
}

function test_basic_progress_no_curses() {
bazel test --experimental_ui --curses=no --color=yes pkg:true 2>$TEST_log \
|| fail "bazel test failed"
# some progress indicator is shown
expect_log '\[[0-9,]* / [0-9,]*\]'
# cursor is not moved up
expect_not_log $'\x1b\[1A'
# no line is deleted
expect_not_log $'\x1b\[K'
# but some green color is used
expect_log $'\x1b\[32m'
}

function test_pass() {
bazel test --experimental_ui --curses=yes --color=yes pkg:true >$TEST_log || fail "bazel test failed"
# PASS is written in green on the same line as the test target
Expand Down

0 comments on commit 759bbfe

Please sign in to comment.