pre-upload: avoid flashing presubmit status lines
The current output will fully erase the status line before redrawing.
When running a bunch of checks after each other, this can cause it to
flash blankly. Instead, we should move the cursor to the start, draw
the new status line over the old one, and then erase anything after
the new one (if the new line is shorter than the old). Since status
lines share a lot of the same form, it's less janky for users as the
common characters never get reset to spaces.
Old:
[RUNNING 33/37 PRESUBMIT.cfg] blah blah
\r<erase>
[RUNNING 34/37 PRESUBMIT.cfg] blah blah
New:
[RUNNING 33/37 PRESUBMIT.cfg] blah blah
\r[RUNNING 34/37 PRESUBMIT.cfg] blah blah<erase>
BUG=None
TEST=`repo upload` still works, and is less flashy
Change-Id: Icc35088e234dc16603cabe496045eb758d5d91d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/repohooks/+/4062228
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 2c3f40d..d2fb9f6 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -3177,6 +3177,8 @@
hook_count,
hook.__name__,
)
+ if isatty:
+ output = f"\r{output}{CSI_ERASE_LINE_AFTER}"
print(output, end="", flush=True)
start_time = datetime.datetime.utcnow()
hook_error = hook(project, commit)