Skip to content

Commit 41fc24b

Browse files
committed
Show progress on TTY terminals
1 parent 14e0e84 commit 41fc24b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

mbed/mbed.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,16 @@ def progress():
178178
sys.stdout.write('\b')
179179

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

187188
def hide_progress(max_width=80):
188-
sys.stdout.write("\r%s\r" % (' ' * max_width))
189+
if sys.stdout.isatty():
190+
sys.stdout.write("\r%s\r" % (' ' * max_width))
189191

190192
# Process execution
191193
class ProcessException(Exception):

0 commit comments

Comments
 (0)