core: add output/detail methods to Ui, prefix with arrows

This commit is contained in:
Mitchell Hashimoto 2014-01-17 11:02:12 -08:00
parent 41e56cb282
commit afbed7e816
2 changed files with 16 additions and 8 deletions

View File

@ -124,7 +124,7 @@ begin
if !Vagrant.in_installer? if !Vagrant.in_installer?
# If we're not in the installer, warn. # If we're not in the installer, warn.
env.ui.warn(I18n.t("vagrant.general.not_in_installer") + "\n") env.ui.warn(I18n.t("vagrant.general.not_in_installer") + "\n", prefix: false)
end end
begin begin

View File

@ -19,7 +19,7 @@ module Vagrant
@logger = Log4r::Logger.new("vagrant::ui::interface") @logger = Log4r::Logger.new("vagrant::ui::interface")
end end
[:ask, :warn, :error, :info, :success].each do |method| [:ask, :detail, :warn, :error, :info, :output, :success].each do |method|
define_method(method) do |message, *opts| define_method(method) do |message, *opts|
# Log normal console messages # Log normal console messages
@logger.info { "#{method}: #{message}" } @logger.info { "#{method}: #{message}" }
@ -104,6 +104,9 @@ module Vagrant
class Basic < Interface class Basic < Interface
include Util::SafePuts include Util::SafePuts
# The prefix for `output` messages.
OUTPUT_PREFIX = "==> "
def initialize def initialize
super super
@ -113,7 +116,7 @@ module Vagrant
# Use some light meta-programming to create the various methods to # Use some light meta-programming to create the various methods to
# output text to the UI. These all delegate the real functionality # output text to the UI. These all delegate the real functionality
# to `say`. # to `say`.
[:info, :warn, :error, :success].each do |method| [:detail, :info, :warn, :error, :output, :success].each do |method|
class_eval <<-CODE class_eval <<-CODE
def #{method}(message, *args) def #{method}(message, *args)
super(message) super(message)
@ -196,10 +199,14 @@ module Vagrant
end end
# This is called by `say` to format the message for output. # This is called by `say` to format the message for output.
def format_message(type, message, opts=nil) def format_message(type, message, **opts)
opts ||= {} prefix = ""
message = "[#{opts[:scope]}] #{message}" if opts[:scope] && opts[:prefix] if !opts.has_key?(:prefix) || opts[:prefix]
message prefix = OUTPUT_PREFIX
prefix = " " * OUTPUT_PREFIX.length if type == :detail
end
prefix + message
end end
end end
@ -212,10 +219,11 @@ module Vagrant
@scope = scope @scope = scope
end end
[:ask, :warn, :error, :info, :success].each do |method| [:ask, :detail, :warn, :error, :info, :output, :success].each do |method|
define_method(method) do |message, opts=nil| define_method(method) do |message, opts=nil|
opts ||= {} opts ||= {}
opts[:scope] = @scope opts[:scope] = @scope
message = "#{@scope}: #{message}" if !opts.has_key?(:prefix) || opts[:prefix]
@ui.send(method, message, opts) @ui.send(method, message, opts)
end end
end end