Skip to content

Commit 759bbfe

Browse files
aehliglberki
authored andcommitted
experimental UI: honor --curses
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
1 parent 63049cc commit 759bbfe

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
public class ExperimentalEventHandler extends BlazeCommandEventHandler {
4343
private static Logger LOG = Logger.getLogger(ExperimentalEventHandler.class.getName());
4444

45+
private final boolean cursorControl;
4546
private final AnsiTerminal terminal;
4647
private final boolean debugAllEvents;
4748
private final ExperimentalStateTracker stateTracker;
@@ -54,6 +55,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
5455
public ExperimentalEventHandler(
5556
OutErr outErr, BlazeCommandEventHandler.Options options, Clock clock) {
5657
super(outErr, options);
58+
this.cursorControl = options.useCursorControl();
5759
this.terminal = new AnsiTerminal(outErr.getErrorStream());
5860
this.terminalWidth = (options.terminalColumns > 0 ? options.terminalColumns : 80);
5961
this.debugAllEvents = options.experimentalUiDebugAllEvents;
@@ -224,6 +226,9 @@ public void resetTerminal() {
224226
}
225227

226228
private void clearProgressBar() throws IOException {
229+
if (!cursorControl) {
230+
return;
231+
}
227232
for (int i = 0; i < numLinesProgressBar; i++) {
228233
terminal.cr();
229234
terminal.cursorUp(1);

src/test/shell/integration/experimental_ui_test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ function test_basic_progress() {
6767
expect_log $'\x1b\[1A\x1b\[K'
6868
}
6969

70+
function test_basic_progress_no_curses() {
71+
bazel test --experimental_ui --curses=no --color=yes pkg:true 2>$TEST_log \
72+
|| fail "bazel test failed"
73+
# some progress indicator is shown
74+
expect_log '\[[0-9,]* / [0-9,]*\]'
75+
# cursor is not moved up
76+
expect_not_log $'\x1b\[1A'
77+
# no line is deleted
78+
expect_not_log $'\x1b\[K'
79+
# but some green color is used
80+
expect_log $'\x1b\[32m'
81+
}
82+
7083
function test_pass() {
7184
bazel test --experimental_ui --curses=yes --color=yes pkg:true >$TEST_log || fail "bazel test failed"
7285
# PASS is written in green on the same line as the test target

0 commit comments

Comments
 (0)