core: make box add UI much icer
This commit is contained in:
parent
c1d5c8f33c
commit
b71cde6b99
|
@ -59,6 +59,8 @@ module Vagrant
|
|||
url = env[:box_url]
|
||||
version = env[:box_version]
|
||||
|
||||
env[:ui].output(I18n.t(
|
||||
"vagrant.box_loading_metadata", name: url))
|
||||
metadata = nil
|
||||
begin
|
||||
metadata_path = download(url, env, ui: false)
|
||||
|
|
|
@ -209,7 +209,10 @@ module Vagrant
|
|||
class_eval <<-CODE
|
||||
def #{method}(message, *args, **opts)
|
||||
super(message)
|
||||
opts[:bold] = #{method.inspect} != :detail if !opts.has_key?(:bold)
|
||||
if !opts.has_key?(:bold)
|
||||
opts[:bold] = #{method.inspect} != :detail && \
|
||||
#{method.inspect} != :ask
|
||||
end
|
||||
@ui.#{method}(format_message(#{method.inspect}, message, **opts), *args, **opts)
|
||||
end
|
||||
CODE
|
||||
|
@ -241,7 +244,8 @@ module Vagrant
|
|||
prefix = ""
|
||||
if !opts.has_key?(:prefix) || opts[:prefix]
|
||||
prefix = OUTPUT_PREFIX
|
||||
prefix = " " * OUTPUT_PREFIX.length if type == :detail
|
||||
prefix = " " * OUTPUT_PREFIX.length if \
|
||||
type == :detail || type == :ask
|
||||
end
|
||||
|
||||
# Fast-path if there is no prefix
|
||||
|
@ -281,16 +285,17 @@ module Vagrant
|
|||
opts[:color] = :green if type == :success
|
||||
opts[:color] = :yellow if type == :warn
|
||||
|
||||
# If there is no color specified, exit early
|
||||
return message if !opts.has_key?(:color)
|
||||
|
||||
# If it is a detail, it is not bold. Every other message type
|
||||
# is bolded.
|
||||
bold = !!opts[:bold]
|
||||
color = COLORS[opts[:color]]
|
||||
colorseq = "#{bold ? 1 : 0 }"
|
||||
if opts[:color]
|
||||
color = COLORS[opts[:color]]
|
||||
colorseq += ";#{color}"
|
||||
end
|
||||
|
||||
# Color the message and make sure to reset the color at the end
|
||||
"\033[#{bold ? 1 : 0};#{color}m#{message}\033[0m"
|
||||
"\033[#{colorseq}m#{message}\033[0m"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -92,7 +92,7 @@ module Vagrant
|
|||
|
||||
output = "Progress: #{columns[0]}% (Rate: #{columns[11]}/s, Estimated time remaining: #{columns[10]})"
|
||||
@ui.clear_line
|
||||
@ui.info(output, :new_line => false)
|
||||
@ui.detail(output, :new_line => false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -111,7 +111,7 @@ module Vagrant
|
|||
|
||||
# Windows doesn't clear properly for some reason, so we just
|
||||
# output one more newline.
|
||||
@ui.info("") if Platform.windows?
|
||||
@ui.detail("") if Platform.windows?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ module VagrantPlugins
|
|||
box_download_ca_cert: options[:ca_cert],
|
||||
box_download_client_cert: options[:client_cert],
|
||||
box_download_insecure: options[:insecure],
|
||||
ui: Vagrant::UI::Prefixed.new(@env.ui, "box"),
|
||||
})
|
||||
|
||||
# Success, exit status 0
|
||||
|
|
|
@ -18,6 +18,8 @@ en:
|
|||
Adding box '%{name}' (v%{version}) for '%{provider}' provider...
|
||||
box_added: |-
|
||||
Successfully added box '%{name}' for '%{provider}'!
|
||||
box_loading_metadata: |-
|
||||
Loading metadata for box '%{name}'
|
||||
cfengine_bootstrapping: |-
|
||||
Bootstrapping CFEngine with policy server: %{policy_server}...
|
||||
cfengine_bootstrapping_policy_hub: |-
|
||||
|
|
|
@ -65,7 +65,7 @@ describe Vagrant::UI::Colored do
|
|||
|
||||
describe "#detail" do
|
||||
it "colors output nothing by default" do
|
||||
subject.should_receive(:safe_puts).with("foo", anything)
|
||||
subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything)
|
||||
subject.detail("foo")
|
||||
end
|
||||
|
||||
|
@ -91,11 +91,16 @@ describe Vagrant::UI::Colored do
|
|||
end
|
||||
|
||||
describe "#output" do
|
||||
it "colors output nothing by default" do
|
||||
subject.should_receive(:safe_puts).with("foo", anything)
|
||||
it "colors output nothing by default, no bold" do
|
||||
subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything)
|
||||
subject.output("foo")
|
||||
end
|
||||
|
||||
it "bolds output without color if specified" do
|
||||
subject.should_receive(:safe_puts).with("\033[1mfoo\033[0m", anything)
|
||||
subject.output("foo", bold: true)
|
||||
end
|
||||
|
||||
it "colors output to color specified in global opts" do
|
||||
subject.opts[:color] = :red
|
||||
|
||||
|
@ -232,6 +237,13 @@ describe Vagrant::UI::Prefixed do
|
|||
|
||||
subject { described_class.new(ui, prefix) }
|
||||
|
||||
describe "#ask" do
|
||||
it "does not request bolding" do
|
||||
ui.should_receive(:ask).with(" #{prefix}: foo", bold: false)
|
||||
subject.ask("foo")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#detail" do
|
||||
it "prefixes with spaces and the message" do
|
||||
ui.should_receive(:safe_puts).with(" #{prefix}: foo", anything)
|
||||
|
|
Loading…
Reference in New Issue