@@ -79,30 +79,36 @@ def download(response)
7979 downloaded += chunk . bytesize
8080 show_progress downloaded , size
8181 end
82+ $stderr. puts
8283 end
8384 downloading_path . rename path
8485 end
8586
8687 def show_progress ( current , size )
87- return unless $stderr. tty?
88- return unless size
88+ progress_rate_available = size && $stderr. tty?
8989
9090 unless @prev
9191 @prev = Time . now
92- $stderr. puts "Downloading #{ @uri } "
92+ $stderr. puts "Downloading #{ @uri } to #{ cache_path } "
9393 end
9494
9595 now = Time . now
96- return if now - @prev < 1 && current < size
97-
98- progress_width = 20
99- progress = current . to_f / size
100- arrow_length = progress * progress_width
101- arrow = "=" * ( arrow_length - 1 ) + ">" + " " * ( progress_width - arrow_length )
102- line = "[#{ arrow } ] (#{ format_bytesize ( current ) } / #{ format_bytesize ( size ) } )"
103- padding = ' ' * ( $stderr. winsize [ 1 ] - line . size )
104- $stderr. print "\r #{ line } #{ padding } "
105- $stderr. puts if current >= size
96+
97+ if progress_rate_available
98+ return if now - @prev < 1 && current < size
99+
100+ progress_width = 20
101+ progress = current . to_f / size
102+ arrow_length = progress * progress_width
103+ arrow = "=" * ( arrow_length - 1 ) + ">" + " " * ( progress_width - arrow_length )
104+ line = "[#{ arrow } ] (#{ format_bytesize ( current ) } / #{ format_bytesize ( size ) } )"
105+ padding = ' ' * ( $stderr. winsize [ 1 ] - line . size )
106+ $stderr. print "\r #{ line } #{ padding } "
107+ else
108+ return if now - @prev < 1
109+
110+ $stderr. print "."
111+ end
106112 @prev = now
107113 end
108114
0 commit comments