Add yardoc to the UI class.
This commit is contained in:
parent
dddc2ad369
commit
ab91117ed7
@ -1,4 +1,7 @@
|
||||
module Guard
|
||||
|
||||
# The UI class helps to format messages for the user.
|
||||
#
|
||||
module UI
|
||||
|
||||
ANSI_ESCAPE_BRIGHT = "1"
|
||||
@ -25,6 +28,12 @@ module Guard
|
||||
|
||||
color_enabled = nil
|
||||
|
||||
# Show an info message.
|
||||
#
|
||||
# @param [String] message the message to show
|
||||
# @param [Hash] options the options
|
||||
# @option options [Boolean] reset whether to clean the output before
|
||||
#
|
||||
def info(message, options = {})
|
||||
unless ENV["GUARD_ENV"] == "test"
|
||||
reset_line if options[:reset]
|
||||
@ -32,6 +41,12 @@ module Guard
|
||||
end
|
||||
end
|
||||
|
||||
# Show a red error message that is prefixed with ERROR.
|
||||
#
|
||||
# @param [String] message the message to show
|
||||
# @param [Hash] options the options
|
||||
# @option options [Boolean] reset whether to clean the output before
|
||||
#
|
||||
def error(message, options = {})
|
||||
unless ENV["GUARD_ENV"] == "test"
|
||||
reset_line if options[:reset]
|
||||
@ -39,6 +54,12 @@ module Guard
|
||||
end
|
||||
end
|
||||
|
||||
# Show a red deprecation message that is prefixed with DEPRECATION.
|
||||
#
|
||||
# @param [String] message the message to show
|
||||
# @param [Hash] options the options
|
||||
# @option options [Boolean] reset whether to clean the output before
|
||||
#
|
||||
def deprecation(message, options = {})
|
||||
unless ENV["GUARD_ENV"] == "test"
|
||||
reset_line if options[:reset]
|
||||
@ -46,6 +67,12 @@ module Guard
|
||||
end
|
||||
end
|
||||
|
||||
# Show a debug message that is prefixed with DEBUG and a timestampe.
|
||||
#
|
||||
# @param [String] message the message to show
|
||||
# @param [Hash] options the options
|
||||
# @option options [Boolean] reset whether to clean the output before
|
||||
#
|
||||
def debug(message, options={ })
|
||||
unless ENV["GUARD_ENV"] == "test"
|
||||
reset_line if options[:reset]
|
||||
@ -53,22 +80,38 @@ module Guard
|
||||
end
|
||||
end
|
||||
|
||||
# Reset a line.
|
||||
#
|
||||
def reset_line
|
||||
print(color_enabled? ? "\r\e[0m" : "\r\n")
|
||||
end
|
||||
|
||||
# Clear the output.
|
||||
#
|
||||
def clear
|
||||
system("clear;")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Reset a color sequence.
|
||||
#
|
||||
# @deprecated
|
||||
# @param [String] text the text
|
||||
#
|
||||
def reset_color(text)
|
||||
deprecation('UI.reset_color(text) is deprecated, please use color(text, "") instead.')
|
||||
color(text, "")
|
||||
end
|
||||
|
||||
# Colorizes a text message.
|
||||
#
|
||||
# @example
|
||||
# color("Hello World", :red, :bright)
|
||||
#
|
||||
# @param [String] the text to colorize
|
||||
# @param [Array] color_options
|
||||
#
|
||||
def color(text, *color_options)
|
||||
color_code = ""
|
||||
color_options.each do |color_option|
|
||||
@ -83,6 +126,10 @@ module Guard
|
||||
color_enabled? ? "\e[0#{ color_code }m#{ text }\e[0m" : text
|
||||
end
|
||||
|
||||
# Checks if color output can be enabled.
|
||||
#
|
||||
# @return [Boolean] whether color is enabled or not
|
||||
#
|
||||
def color_enabled?
|
||||
if @color_enabled.nil?
|
||||
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
||||
@ -102,6 +149,7 @@ module Guard
|
||||
@color_enabled = true
|
||||
end
|
||||
end
|
||||
|
||||
@color_enabled
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user