Class: Vli::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 Vli::Util::SafePuts
Methods inherited from Interface
Constructor Details
This class inherits a constructor from Vli::UI::Interface
Instance Method Details
#format_message(type, message, opts = nil) ⇒ Object
This is called by ‘say` to format the message for output.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/vli/ui.rb', line 144 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 |