Class: Vagrant::UI::Prefixed
Overview
Prefixed wraps an existing UI and adds a prefix to it.
Constant Summary collapse
- OUTPUT_PREFIX =
The prefix for
output
messages. "==> "
Instance Attribute Summary
Attributes inherited from Interface
Instance Method Summary collapse
- #client ⇒ Object
- #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.
- #rewriting ⇒ Object
- #to_proto ⇒ Object
Methods inherited from Interface
Constructor Details
#initialize(ui, prefix) ⇒ Prefixed
Returns a new instance of Prefixed.
300 301 302 303 304 305 |
# File 'lib/vagrant/ui.rb', line 300 def initialize(ui, prefix) super() @prefix = prefix @ui = ui end |
Instance Method Details
#client ⇒ Object
311 312 313 |
# File 'lib/vagrant/ui.rb', line 311 def client @ui.client end |
#format_message(type, message, **opts) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/vagrant/ui.rb', line 363 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
315 316 317 318 |
# File 'lib/vagrant/ui.rb', line 315 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.
348 349 350 351 352 353 354 |
# File 'lib/vagrant/ui.rb', line 348 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.
359 360 361 |
# File 'lib/vagrant/ui.rb', line 359 def opts @ui.opts end |
#rewriting ⇒ Object
398 399 400 401 402 |
# File 'lib/vagrant/ui.rb', line 398 def rewriting @ui.rewriting do |ui| yield ui end end |
#to_proto ⇒ Object
307 308 309 |
# File 'lib/vagrant/ui.rb', line 307 def to_proto @ui.to_proto end |