Add color to the colored UI
This commit is contained in:
parent
af56c274c0
commit
d84ec88fae
|
@ -88,6 +88,19 @@ module Vagrant
|
||||||
# of messages. This should only be used with a TTY that supports color,
|
# 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.
|
# but is up to the user of the class to verify this is the case.
|
||||||
class Colored < Interface
|
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
|
# Use some light meta-programming to create the various methods to
|
||||||
# output text to the UI. These all delegate the real functionality
|
# output text to the UI. These all delegate the real functionality
|
||||||
# to `say`.
|
# to `say`.
|
||||||
|
@ -137,6 +150,9 @@ module Vagrant
|
||||||
# Format the message
|
# Format the message
|
||||||
message = "[#{env.resource}] #{message}" if opts[:prefix]
|
message = "[#{env.resource}] #{message}" if opts[:prefix]
|
||||||
|
|
||||||
|
# Colorize the message
|
||||||
|
message = "#{COLOR_MAP[type]}#{message}#{CLEAR}" if COLOR_MAP[type]
|
||||||
|
|
||||||
# Output!
|
# Output!
|
||||||
# TODO: Color
|
# TODO: Color
|
||||||
channel.send(printer, message)
|
channel.send(printer, message)
|
||||||
|
|
Loading…
Reference in New Issue