class Vagrant::UI::Prefixed

Prefixed wraps an existing UI and adds a prefix to it.

Constants

OUTPUT_PREFIX

The prefix for `output` messages.

Public Class Methods

new(ui, prefix) click to toggle source
Calls superclass method Vagrant::UI::Interface.new
# File lib/vagrant/ui.rb, line 233
def initialize(ui, prefix)
  super()

  @prefix = prefix
  @ui     = ui
end

Public Instance Methods

format_message(type, message, **opts) click to toggle source
# File lib/vagrant/ui.rb, line 283
def format_message(type, message, **opts)
  opts = self.opts.merge(opts)

  prefix = ""
  if !opts.has_key?(:prefix) || opts[:prefix]
    prefix = OUTPUT_PREFIX
    prefix = " " * OUTPUT_PREFIX.length if              type == :detail || type == :ask || opts[:prefix_spaces]
  end

  # Fast-path if there is no prefix
  return message if prefix.empty?

  # Otherwise, make sure to prefix every line properly
  message.split("\n").map do |line|
    "#{prefix}#{@prefix}: #{line}"
  end.join("\n")
end
initialize_copy(original) click to toggle source
Calls superclass method Vagrant::UI::Interface#initialize_copy
# File lib/vagrant/ui.rb, line 240
def initialize_copy(original)
  super
  @ui = original.instance_variable_get(:@ui).dup
end
machine(type, *data) click to toggle source

For machine-readable output, set the prefix in the options hash and continue it on.

# File lib/vagrant/ui.rb, line 268
def machine(type, *data)
  opts = {}
  opts = data.pop if data.last.is_a?(Hash)
  opts[:target] = @prefix
  data << opts
  @ui.machine(type, *data)
end
opts() click to toggle source

Return the parent's opts.

@return [Hash]

# File lib/vagrant/ui.rb, line 279
def opts
  @ui.opts
end