-
Notifications
You must be signed in to change notification settings - Fork 179
UX: Add progress bar for both Git and Mercurial when using non-verbose mode #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
fa7cd39
to
8a3d686
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, supposing the answer to my question is Yes.
mbed/mbed.py
Outdated
sys.stdout.write('\b') | ||
|
||
def hide_progress(): | ||
sys.stdout.write("\033[K\r\b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little magic. Does this work cross platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked it on Mac OS, Linux, Windows 7 and Windows 10.
Esc[K means Clear line from cursor right
Escape sequences are standardized for years for ANSI/VT-100 compatible terminals. http://ascii-table.com/ansi-escape-sequences-vt-100.php.
Not sure how this would look in a Jenkins log though as it's not a terminal. Any ideas how we could test with Jenkins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that on Windows there's a parasite character. Pending minor patch to solve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theotherjimmy Magic removed in favour of more standard cursor handling :)
mbed/mbed.py
Outdated
percent = round(float(percent), 2) | ||
show_percent = '%.2f' % percent | ||
line = str(title) + ' |' | ||
bwidth = max_width - len(str(title)) - len(show_percent) - 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 6
seems a litte magic. Is it len(' |') + len('| ') + len('%') + len('\r')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the ones you mentioned + an extra character as on some terminals (like Windows) printing exactly 80 characters, produces a new line.
mbed/mbed.py
Outdated
def hide_progress(max_width=80): | ||
line = '' | ||
for i in range(0, max_width): | ||
line += ' ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 lines could be:
line = ' ' * max_width
Up to you. I have a preference for the shorter version because I think it better conveys the intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you spotted this. Will change it shortly.
mbed/mbed.py
Outdated
else: | ||
break | ||
|
||
stdout, stderr = proc.communicate(stdin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we started using stderr
here, so it may be best to revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff looks great! Thanks!
This PR adds
The progress bar is only visible when mbed CLI is in non-verbose mode (no
-v
or-vv
).Git example:
Hg example:
Note that with Mercurial/Hg the progress bar appears late because of the progress reported late by Mercurial.
Backwards compatbility
This PR is fully backwards compatible
Documentation
No documentation is needed