Move UI to remote file and include options to client

This commit is contained in:
Chris Roberts 2021-08-20 08:59:47 -07:00 committed by Paul Hinze
parent df53588de5
commit e090fa4e10
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 33 additions and 25 deletions

View File

@ -9,6 +9,7 @@ require "vagrant/util/safe_puts"
module Vagrant
module UI
autoload :Remote, "vagrant/ui/remote"
# Vagrant UIs handle communication with the outside world (typically
# through a shell). They must respond to the following methods:
#
@ -283,31 +284,6 @@ module Vagrant
end
end
class RemoteUI < Basic
def initialize(client)
super()
@client = client
end
def clear_line
# no-op
end
# This method handles actually outputting a message of a given type
# to the console.
def say(type, message, opts={})
@client.output([message.gsub("%", "%%")])
end
[:detail, :info, :warn, :error, :output, :success].each do |method|
class_eval <<-CODE
def #{method}(message, *args)
say(#{method.inspect}, message, *args)
end
CODE
end
end
# Prefixed wraps an existing UI and adds a prefix to it.
class Prefixed < Interface
# The prefix for `output` messages.

32
lib/vagrant/ui/remote.rb Normal file
View File

@ -0,0 +1,32 @@
module Vagrant
module UI
class RemoteUI < Basic
def initialize(client)
super()
@client = client
end
def clear_line
# no-op
end
# This method handles actually outputting a message of a given type
# to the console.
def say(type, message, opts={})
if !opts.key?(:new_line)
opts[:new_line] = true
end
opts[:style] = type.to_sym
@client.output([message.gsub("%", "%%")], **opts)
end
[:detail, :info, :warn, :error, :output, :success].each do |method|
class_eval <<-CODE
def #{method}(message, *args)
say(#{method.inspect}, message, *args)
end
CODE
end
end
end
end