Class: Vagrant::UI::Colored
Overview
This is a UI implementation that outputs color for various types of messages. This should only be used with a TTY that supports color, but is up to the user of the class to verify this is the case.
Constant Summary collapse
- COLORS =
Terminal colors
{ :clear => "\e[0m", :red => "\e[31m", :green => "\e[32m", :yellow => "\e[33m" }
- COLOR_MAP =
Mapping between type of message and the color to output
{ :warn => COLORS[:yellow], :error => COLORS[:red], :success => COLORS[:green] }
Instance Attribute Summary
Attributes inherited from Interface
Instance Method Summary collapse
-
#format_message(type, message, opts = nil) ⇒ Object
This is called by
say
to format the message for output.
Methods inherited from Basic
#ask, #clear_line, #report_progress, #say
Methods included from Vagrant::Util::SafePuts
Methods inherited from Interface
Constructor Details
This class inherits a constructor from Vagrant::UI::Interface
Instance Method Details
#format_message(type, message, opts = nil) ⇒ Object
This is called by say
to format the message for output.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/vagrant/ui.rb', line 151 def (type, , opts=nil) # Get the format of the message before adding color. = super # Colorize the message if there is a color for this type of message, # either specified by the options or via the default color map. if opts.has_key?(:color) color = COLORS[opts[:color]] = "#{color}#{}#{COLORS[:clear]}" else = "#{COLOR_MAP[type]}#{}#{COLORS[:clear]}" if COLOR_MAP[type] end end |