@@ -30,6 +30,7 @@ binaryen_git_repo = 'https://github.com/WebAssembly/binaryen.git'
30
30
31
31
# Enable this to do very verbose printing about the different steps that are being run. Useful for debugging.
32
32
VERBOSE = bool (os .getenv ('EMSDK_VERBOSE' )) if os .getenv ('EMSDK_VERBOSE' ) != None else False
33
+ TTY_OUTPUT = sys .stdout .isatty ()
33
34
34
35
POWERSHELL = bool (os .getenv ('EMSDK_POWERSHELL' ))
35
36
@@ -473,18 +474,31 @@ def download_file(url, dstpath, download_even_if_exists=False, filename_prefix =
473
474
else : print ("Downloading: %s from %s" % (file_name , url ))
474
475
475
476
file_size_dl = 0
477
+ # Draw a progress bar 80 chars wide (in non-TTY mode)
478
+ progress_max = 80 - 4
479
+ progress_shown = 0
476
480
block_sz = 8192
481
+ if not TTY_OUTPUT :
482
+ print (' [' , end = '' )
477
483
while True :
478
484
buffer = u .read (block_sz )
479
485
if not buffer :
480
486
break
481
487
482
488
file_size_dl += len (buffer )
483
489
f .write (buffer )
484
- if sys .stdout .isatty () and file_size :
485
- status = r"%10d [%3.2f%%]" % (file_size_dl , file_size_dl * 100. / file_size )
486
- status = status + chr (8 )* (len (status )+ 1 )
487
- print (status , end = ' ' )
490
+ if file_size :
491
+ percent = file_size_dl * 100.0 / file_size
492
+ if TTY_OUTPUT :
493
+ status = r" %10d [%3.02f%%]" % (file_size_dl , percent )
494
+ print (status , end = '\r ' )
495
+ else :
496
+ while progress_shown < progress_max * percent / 100 :
497
+ print ('-' , end = '' )
498
+ sys .stdout .flush ()
499
+ progress_shown += 1
500
+ if not TTY_OUTPUT :
501
+ print (']' )
488
502
except Exception as e :
489
503
print ("Error downloading URL '" + url + "': " + str (e ))
490
504
rmfile (file_name )
@@ -2131,6 +2145,11 @@ def main():
2131
2145
arg_uses = extract_bool_arg ('--uses' )
2132
2146
arg_global = extract_bool_arg ('--global' )
2133
2147
arg_embedded = extract_bool_arg ('--embedded' )
2148
+ arg_notty = extract_bool_arg ('--notty' )
2149
+ if arg_notty :
2150
+ global TTY_OUTPUT
2151
+ TTY_OUTPUT = False
2152
+
2134
2153
cmd = sys .argv [1 ]
2135
2154
2136
2155
# On first run when tag list is not present, populate it to bootstrap.
0 commit comments