Add color to the colored UI

This commit is contained in:
Mitchell Hashimoto 2011-11-27 16:33:43 -07:00
parent af56c274c0
commit d84ec88fae
1 changed files with 16 additions and 0 deletions

View File

@ -88,6 +88,19 @@ module Vagrant
# 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.
class Colored < Interface
# Terminal colors
CLEAR = "\e[0m"
YELLOW = "\e[33m"
RED = "\e[31m"
GREEN = "\e[32m"
# Mapping between type of message and the color to output
COLOR_MAP = {
:warn => YELLOW,
:error => RED,
:success => GREEN
}
# Use some light meta-programming to create the various methods to
# output text to the UI. These all delegate the real functionality
# to `say`.
@ -137,6 +150,9 @@ module Vagrant
# Format the message
message = "[#{env.resource}] #{message}" if opts[:prefix]
# Colorize the message
message = "#{COLOR_MAP[type]}#{message}#{CLEAR}" if COLOR_MAP[type]
# Output!
# TODO: Color
channel.send(printer, message)