Skip to content

Show progress only on tty terminals #612

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 1 commit into from
Jan 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ def progress():
sys.stdout.write('\b')

def show_progress(title, percent, max_width=80):
percent = round(float(percent), 2)
show_percent = '%.2f' % percent
bwidth = max_width - len(str(title)) - len(show_percent) - 6 # 6 equals the spaces and paddings between title, progress bar and percentage
sys.stdout.write('%s |%s%s| %s%%\r' % (str(title), '#' * int(percent * bwidth // 100), '-' * (bwidth - int(percent * bwidth // 100)), show_percent))
sys.stdout.flush()
if sys.stdout.isatty():
percent = round(float(percent), 2)
show_percent = '%.2f' % percent
bwidth = max_width - len(str(title)) - len(show_percent) - 6 # 6 equals the spaces and paddings between title, progress bar and percentage
sys.stdout.write('%s |%s%s| %s%%\r' % (str(title), '#' * int(percent * bwidth // 100), '-' * (bwidth - int(percent * bwidth // 100)), show_percent))
sys.stdout.flush()

def hide_progress(max_width=80):
sys.stdout.write("\r%s\r" % (' ' * max_width))
if sys.stdout.isatty():
sys.stdout.write("\r%s\r" % (' ' * max_width))

# Process execution
class ProcessException(Exception):
Expand Down