Yield output based on ui opts
This commit is contained in:
parent
fdd81a8641
commit
c5a5b3d0b2
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user