From afbed7e8164f8bf5dc2b5665dbbc46c005781b85 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Jan 2014 11:02:12 -0800 Subject: [PATCH] core: add output/detail methods to Ui, prefix with arrows --- bin/vagrant | 2 +- lib/vagrant/ui.rb | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 631b35f3b..21c22fedb 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -124,7 +124,7 @@ begin if !Vagrant.in_installer? # 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 begin diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index d7f11dd04..96bd8a6d7 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -19,7 +19,7 @@ module Vagrant @logger = Log4r::Logger.new("vagrant::ui::interface") 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| # Log normal console messages @logger.info { "#{method}: #{message}" } @@ -104,6 +104,9 @@ module Vagrant class Basic < Interface include Util::SafePuts + # The prefix for `output` messages. + OUTPUT_PREFIX = "==> " + def initialize super @@ -113,7 +116,7 @@ module Vagrant # Use some light meta-programming to create the various methods to # output text to the UI. These all delegate the real functionality # to `say`. - [:info, :warn, :error, :success].each do |method| + [:detail, :info, :warn, :error, :output, :success].each do |method| class_eval <<-CODE def #{method}(message, *args) super(message) @@ -196,10 +199,14 @@ module Vagrant end # This is called by `say` to format the message for output. - def format_message(type, message, opts=nil) - opts ||= {} - message = "[#{opts[:scope]}] #{message}" if opts[:scope] && opts[:prefix] - message + def format_message(type, message, **opts) + prefix = "" + if !opts.has_key?(:prefix) || opts[:prefix] + prefix = OUTPUT_PREFIX + prefix = " " * OUTPUT_PREFIX.length if type == :detail + end + + prefix + message end end @@ -212,10 +219,11 @@ module Vagrant @scope = scope 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| opts ||= {} opts[:scope] = @scope + message = "#{@scope}: #{message}" if !opts.has_key?(:prefix) || opts[:prefix] @ui.send(method, message, opts) end end