diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index ee3547fc8..2a8c8de05 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -32,7 +32,7 @@ module Vagrant def initialize @logger = Log4r::Logger.new("vagrant::ui::interface") - @opts = {} + @opts = { :show_progress => true } @stdin = $stdin @stdout = $stdout @@ -75,6 +75,12 @@ module Vagrant def machine(type, *data) @logger.info("Machine: #{type} #{data.inspect}") end + + def output_if_showing_progress + if @opts[:show_progress] == true + yield self + end + end end # This is a UI implementation that does nothing. diff --git a/lib/vagrant/util/curl_helper.rb b/lib/vagrant/util/curl_helper.rb index 67def5a82..07afa3e70 100644 --- a/lib/vagrant/util/curl_helper.rb +++ b/lib/vagrant/util/curl_helper.rb @@ -82,10 +82,11 @@ module Vagrant # 9 - Time spent # 10 - Time left # 11 - Current speed - output = "Progress: #{columns[0]}% (Rate: #{columns[11]}/s, Estimated time remaining: #{columns[10]})" - ui.clear_line - ui.detail(output, new_line: false) + ui.output_if_showing_progress do |ui| + ui.clear_line + ui.detail(output, new_line: false) + end end end diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index 5cc1722d8..e84871078 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -110,6 +110,18 @@ describe Vagrant::UI::Basic do subject.detail(output) end end + + context "#output_if_showing_progress" do + it "yields an output" do + subject.opts[:show_progress] = true + expect { |b| subject.output_if_showing_progress(&b) }.to yield_control + end + + it "does not yield an output" do + subject.opts[:show_progress] = false + expect { |b| subject.output_if_showing_progress(&b) }.to_not yield_control + end + end end describe Vagrant::UI::Colored do