Merge pull request #11126 from chrisroberts/f-newline-output
Update UI to properly retain newlines when adding prefix
This commit is contained in:
commit
ce20b70073
|
@ -329,10 +329,15 @@ module Vagrant
|
||||||
target = opts[:target] if opts.key?(:target)
|
target = opts[:target] if opts.key?(:target)
|
||||||
target = "#{target}:" if target != ""
|
target = "#{target}:" if target != ""
|
||||||
|
|
||||||
# Get the lines. The first default is because if the message
|
|
||||||
# is an empty string, then we want to still use the empty string.
|
|
||||||
lines = [message]
|
lines = [message]
|
||||||
lines = message.split("\n") if message != ""
|
if message != ""
|
||||||
|
lines = [].tap do |l|
|
||||||
|
message.scan(/(.*?)(\n|$)/).each do |m|
|
||||||
|
l << m.first if m.first != "" || (m.first == "" && m.last == "\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
lines << "" if message.end_with?("\n")
|
||||||
|
end
|
||||||
|
|
||||||
# Otherwise, make sure to prefix every line properly
|
# Otherwise, make sure to prefix every line properly
|
||||||
lines.map do |line|
|
lines.map do |line|
|
||||||
|
|
|
@ -406,4 +406,17 @@ describe Vagrant::UI::Prefixed do
|
||||||
subject.output("foo", target: "bar")
|
subject.output("foo", target: "bar")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#format_message" do
|
||||||
|
it "should return the same number of new lines as given" do
|
||||||
|
["no new line", "one\nnew line", "two\nnew lines\n", "three\nnew lines\n\n"].each do |msg|
|
||||||
|
expect(subject.format_message(:detail, msg).count("\n")).to eq(msg.count("\n"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should properly format a blank message" do
|
||||||
|
expect(subject.format_message(:detail, "", target: "default", prefix: true)).
|
||||||
|
to match(/\s+default:\s+/)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue