Skip to content

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

Merged
merged 5 commits into from
Jan 12, 2018

Conversation

screamerbg
Copy link
Contributor

@screamerbg screamerbg commented Dec 22, 2017

This PR adds

  • Progress bar for both Git and Mercurial when cloning

The progress bar is only visible when mbed CLI is in non-verbose mode (no -v or -vv).

Git example:

/tmp:$ mbed import mbed-os-example-client
[mbed] Importing program "mbed-os-example-client" from "https://github.com/ARMmbed/mbed-os-example-client" at latest revision in the current branch
[mbed] Adding library "easy-connect" from "https://github.com/ARMmbed/easy-connect" at rev #6af200df4817
[mbed] Adding library "easy-connect/atmel-rf-driver" from "https://github.com/ARMmbed/atmel-rf-driver" at rev #2cd9abba3e37
[mbed] Adding library "easy-connect/esp8266-driver" from "https://github.com/ARMmbed/esp8266-driver" at rev #b0d79dad507d
[mbed] Adding library "easy-connect/mcr20a-rf-driver" from "https://github.com/ARMmbed/mcr20a-rf-driver" at rev #9aac10474702
[mbed] Adding library "easy-connect/stm-spirit1-rf-driver" from "https://github.com/ARMmbed/stm-spirit1-rf-driver" at rev #0ff4ca7537f0
[mbed] Adding library "easy-connect/wifi-x-nucleo-idw01m1" from "https://github.com/ARMmbed/wifi-x-nucleo-idw01m1" at rev #537b01c4a053
[mbed] Adding library "mbed-client" from "https://github.com/ARMmbed/mbed-client" at rev #ea04c5de7822
[mbed] Adding library "mbed-client/mbed-client-c" from "https://github.com/ARMmbed/mbed-client-c" at rev #ecfa619e42b2
[mbed] Adding library "mbed-client/mbed-client-classic" from "https://github.com/ARMmbed/mbed-client-classic" at rev #4e66929607c3
[mbed] Adding library "mbed-client/mbed-client-mbed-tls" from "https://github.com/ARMmbed/mbed-client-mbed-tls" at rev #7e1b6d815038
[mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at rev #8b54959f5bca
Downloading |##########------------------------------------------------| 16.17%

Hg example:

/tmp/1:$ mbed import https://os.mbed.com/users/mbed_official/code/mbed-dev
[mbed] Importing program "mbed-dev" from "https://os.mbed.com/users/mbed_official/code/mbed-dev" at latest revision in the current branch
Downloading |######################------------------------------------| 36.75%

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

Copy link
Contributor

@sg- sg- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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")
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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')?

Copy link
Contributor Author

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 += ' '
Copy link
Contributor

@theotherjimmy theotherjimmy Jan 10, 2018

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted. Thanks

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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!

@screamerbg screamerbg merged commit 14e0e84 into ARMmbed:master Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants