From 535f82e1921a3fd15d3bc04cc3d71ebd97aecbda Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 25 Feb 2022 15:58:27 -0800 Subject: [PATCH] Update remote UI implementation to retain formatting --- lib/vagrant/ui/remote.rb | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/vagrant/ui/remote.rb b/lib/vagrant/ui/remote.rb index de1f6d807..c9346de58 100644 --- a/lib/vagrant/ui/remote.rb +++ b/lib/vagrant/ui/remote.rb @@ -1,5 +1,19 @@ module Vagrant module UI + module Reformatter + def format_message(type, message, **opts) + message = super + opts[:style] = type + [message, opts] + end + end + + class Interface + def self.inherited(klass) + klass.prepend(Reformatter) + end + end + class Remote < Basic attr_reader :client @@ -9,7 +23,7 @@ module Vagrant end def clear_line - # no-op + @client.clear_line end def ask(message, **opts) @@ -17,22 +31,15 @@ module Vagrant @client.input(message.gsub("%", "%%"), **opts) 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 + def safe_puts(message, **opts) + message, extra_opts = message + opts = { + new_line: opts[:printer] == :puts, + style: extra_opts[:style], + bold: extra_opts[:bold] + } - [:detail, :info, :warn, :error, :output, :success].each do |method| - class_eval <<-CODE - def #{method}(message, *args) - say(#{method.inspect}, message, *args) - end - CODE + client.output(message.gsub("%", "%%"), **opts) end def to_proto