@@ -46,14 +46,20 @@ function Step([string] $message) {
4646}
4747function Draw-Download ([long ] $bytes , [long ] $total ) {
4848 if (-not $interactive ) { return }
49- if ($total -gt 0 ) {
49+ $columns = [Console ]::WindowWidth
50+ if ($columns -le 0 ) { $columns = 80 }
51+ if ($total -gt 0 -and $columns -ge 9 ) {
5052 $percent = [Math ]::Min(100 , [Math ]::Floor($bytes * 100.0 / $total ))
51- $filled = [int ][Math ]::Floor($percent * 32 / 100 )
53+ $width = [Math ]::Min(32 , $columns - 8 )
54+ $filled = [int ][Math ]::Floor($percent * $width / 100 )
5255 $bar = ([string ][char ]0x25A0 ) * $filled
53- $rest = ([string ][char ]0x00B7 ) * (32 - $filled )
54- [Console ]::Error.Write((" `r $esc [2K $accent$bar$reset$muted$rest$reset {0,3}% $muted {1:F1} / {2:F1} MB$reset " -f $percent , ($bytes / 1 MB ), ($total / 1 MB )))
56+ $rest = ([string ][char ]0x00B7 ) * ($width - $filled )
57+ $sizes = (" {0:F1} / {1:F1} MB" -f ($bytes / 1 MB ), ($total / 1 MB ))
58+ if ($width + 7 + $sizes.Length -ge $columns ) { $sizes = " " }
59+ [Console ]::Error.Write((" `r $esc [2K $accent$bar$reset$muted$rest$reset {0,3}%" -f $percent ) + " $muted$sizes$reset " )
5560 } else {
56- [Console ]::Error.Write((" `r $esc [2K ${muted} Downloading$reset {0:F1} MB" -f ($bytes / 1 MB )))
61+ $line = if ($columns -ge 32 ) { " Downloading {0:F1} MB" -f ($bytes / 1 MB ) } else { " {0:F1} MB" -f ($bytes / 1 MB ) }
62+ [Console ]::Error.Write(" `r $esc [2K" + $line.Substring (0 , [Math ]::Min($line.Length , $columns - 1 )))
5763 }
5864}
5965function Fetch ([string ] $uri , [string ] $destination , [switch ] $progress ) {
0 commit comments