Yield output based on ui opts

This commit is contained in:
sophia 2020-03-26 15:44:16 -04:00
parent fdd81a8641
commit c5a5b3d0b2
3 changed files with 23 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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