Class: Vagrant::UI::Remote

Inherits:
Basic show all
Defined in:
lib/vagrant/ui/remote.rb

Instance Attribute Summary collapse

Attributes inherited from Interface

#opts, #stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from Basic

#format_message, #report_progress, #say

Methods inherited from Interface

#color?, inherited, #initialize_copy, #rewriting

Constructor Details

#initialize(client) ⇒ Remote

Returns a new instance of Remote.



23
24
25
26
27
# File 'lib/vagrant/ui/remote.rb', line 23

def initialize(client)
  super()
  @client = client
  @logger = Log4r::Logger.new("vagrant::ui")
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



21
22
23
# File 'lib/vagrant/ui/remote.rb', line 21

def client
  @client
end

Instance Method Details

#ask(message, **opts) ⇒ Object



33
34
35
36
37
# File 'lib/vagrant/ui/remote.rb', line 33

def ask(message, **opts)
  opts[:style] ||= :detail
  opts[:echo] = true if !opts.key?(:echo)
  @client.input(message.gsub("%", "%%"), **opts)
end

#clear_lineObject



29
30
31
# File 'lib/vagrant/ui/remote.rb', line 29

def clear_line
  @client.clear_line
end

#machine(type, *data) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/vagrant/ui/remote.rb', line 51

def machine(type, *data)
  if !client.is_machine_readable
    @logger.info("Machine: #{type} #{data.inspect}")
    return
  end

  opts = {}
  opts = data.pop if data.last.kind_of?(Hash)
  target = opts[:target] || ""

  # Prepare the data by replacing characters that aren't outputted
  data.each_index do |i|
    data[i] = data[i].to_s.dup
    data[i].gsub!(",", "%!(VAGRANT_COMMA)")
    data[i].gsub!("\n", "\\n")
    data[i].gsub!("\r", "\\r")
  end
  table_data = {
    rows: [[Time.now.utc.to_i, target, type, data.join(",")]]
  }

  client.table(table_data, **opts)
end

#safe_puts(message, **opts) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant/ui/remote.rb', line 39

def safe_puts(message, **opts)
  message, extra_opts = message
  opts = {
    new_line: opts[:printer] == :puts,
    style: extra_opts[:style],
    bold: extra_opts[:bold],
    color: extra_opts[:color]
  }

  client.output(message.gsub("%", "%%"), **opts)
end

#to_protoObject



75
76
77
# File 'lib/vagrant/ui/remote.rb', line 75

def to_proto
  @client.proto
end