lib/u3d/utils.rb in u3d-1.0.2 vs lib/u3d/utils.rb in u3d-1.0.3

- old
+ new

@@ -62,10 +62,11 @@ def download_file(path, url, size: nil) File.open(path, 'wb') do |f| uri = URI(url) current = 0 last_print_update = 0 + print_progress = UI.interactive? || U3dCore::Globals.verbose? Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| request = Net::HTTP::Get.new uri http.request request do |response| begin size ||= Integer(response['Content-Length']) @@ -77,21 +78,22 @@ f.write(segment) current += segment.length # wait for Net::HTTP buffer on slow networks # FIXME revisits, this slows down download on fast network # sleep 0.08 # adjust to reduce CPU - next unless UI.interactive? + next unless print_progress next unless Time.now.to_f - last_print_update > 0.5 last_print_update = Time.now.to_f if size Utils.print_progress(current, size, started_at) else Utils.print_progress_nosize(current, started_at) end + print "\n" unless UI.interactive? end end end - print "\n" if UI.interactive? + print "\n" if print_progress end end def get_url_content_length(url) UI.verbose "get_url_content_length #{url}"