Class: Vagrant::UI::Prefixed
Overview
Prefixed wraps an existing UI and adds a prefix to it.
Constant Summary collapse
- OUTPUT_PREFIX =
The prefix for
outputmessages. "==> "
Instance Attribute Summary
Attributes inherited from Interface
Instance Method Summary collapse
- #format_message(type, message, **opts) ⇒ Object
-
#initialize(ui, prefix) ⇒ Prefixed
constructor
A new instance of Prefixed.
- #initialize_copy(original) ⇒ Object
-
#machine(type, *data) ⇒ Object
For machine-readable output, set the prefix in the options hash and continue it on.
-
#opts ⇒ Hash
Return the parent's opts.
Methods inherited from Interface
Constructor Details
#initialize(ui, prefix) ⇒ Prefixed
Returns a new instance of Prefixed.
260 261 262 263 264 265 |
# File 'lib/vagrant/ui.rb', line 260 def initialize(ui, prefix) super() @prefix = prefix @ui = ui end |
Instance Method Details
#format_message(type, message, **opts) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/vagrant/ui.rb', line 313 def (type, , **opts) opts = self.opts.merge(opts) prefix = "" if !opts.key?(:prefix) || opts[:prefix] prefix = OUTPUT_PREFIX prefix = " " * OUTPUT_PREFIX.length if \ type == :detail || type == :ask || opts[:prefix_spaces] end = Util::CredentialScrubber.desensitize() # Fast-path if there is no prefix return if prefix.empty? target = @prefix target = opts[:target] if opts.key?(:target) target = "#{target}:" if target != "" lines = [] if != "" lines = [].tap do |l| .scan(/(.*?)(\n|$)/).each do |m| l << m.first if m.first != "" || (m.first == "" && m.last == "\n") end end lines << "" if .end_with?("\n") end # Otherwise, make sure to prefix every line properly lines.map do |line| "#{prefix}#{target} #{line}" end.join("\n") end |
#initialize_copy(original) ⇒ Object
267 268 269 270 |
# File 'lib/vagrant/ui.rb', line 267 def initialize_copy(original) super @ui = original.instance_variable_get(:@ui).dup end |
#machine(type, *data) ⇒ Object
For machine-readable output, set the prefix in the options hash and continue it on.
298 299 300 301 302 303 304 |
# File 'lib/vagrant/ui.rb', line 298 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 ⇒ Hash
Return the parent's opts.
309 310 311 |
# File 'lib/vagrant/ui.rb', line 309 def opts @ui.opts end |