From b557ee56253485b583d9cf86a1bcef6c25d5c416 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Jan 2014 18:04:32 -0800 Subject: [PATCH] core: align text and make sure its all lined up with prefixes --- lib/vagrant/ui.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 03c75ce1d..50b9ca3ae 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -211,7 +211,11 @@ module Vagrant prefix = " " * OUTPUT_PREFIX.length if type == :detail end - prefix + message + # Fast-path if there is no prefix + return message if prefix.empty? + + # Otherwise, make sure to prefix every line properly + message.split("\n").map { |line| "#{prefix}#{line}" }.join("\n") end end @@ -235,7 +239,16 @@ module Vagrant define_method(method) do |message, opts=nil| opts ||= {} opts[:scope] = @scope - message = "#{@scope}: #{message}" if !opts.has_key?(:prefix) || opts[:prefix] + if !opts.has_key?(:prefix) || opts[:prefix] + first = true + prefix = "#{@scope}: " + prefix_blank = " " * prefix.length + message = message.split("\n").map do |line| + scope = first ? prefix : prefix_blank + first = false + "#{scope}#{line}" + end.join("\n") + end @ui.send(method, message, opts) end end