The UI class helps to format messages for the user. Everything that is logged through this class is considered either as an error message or a diagnostic message and is written to standard error ($stderr).
If your Guard plugin does some output that is piped into another process for further processing, please just write it to STDOUT with `puts`.
Black background color
Blue background color
Cyan background color
Green background color
Magenta background color
Red background color
White background color
Yellow background color
Black foreground color
Blue foreground color
Brighten the color
Cyan foreground color
Green foreground color
Magenta foreground color
Red foreground color
White foreground color
Yellow foreground color
Show a scoped action message.
@param [String] action the action to show @param [Hash] scopes hash with a guard or a group scope
# File lib/guard/ui.rb, line 136 def action_with_scopes(action, scopes) plugins = scopes[:plugins] || [] groups = scopes[:groups] || [] if plugins.empty? && groups.empty? plugins = ::Guard.scope[:plugins] || [] groups = ::Guard.scope[:groups] || [] end scope_message ||= plugins.join(',') unless plugins.empty? scope_message ||= groups.join(',') unless groups.empty? scope_message ||= 'all' info "#{ action } #{ scope_message }" end
Clear the output if clearable.
# File lib/guard/ui.rb, line 118 def clear(options = {}) if ::Guard.options[:clear] && (@clearable || options[:force]) @clearable = false system('clear;') end end
Allow the screen to be cleared again.
# File lib/guard/ui.rb, line 127 def clearable @clearable = true end
Show a debug message that is prefixed with DEBUG and a timestamp.
@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin
# File lib/guard/ui.rb, line 103 def debug(message, options = { }) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.debug(color(message, :yellow), plugin) end end
Show a red deprecation message that is prefixed with DEPRECATION. It has a log level of `warn`.
@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin
# File lib/guard/ui.rb, line 90 def deprecation(message, options = { }) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.warn(color(message, :yellow), plugin) end end
Show a red error message that is prefixed with ERROR.
@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin
# File lib/guard/ui.rb, line 76 def error(message, options = { }) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.error(color(message, :red), plugin) end end
Show an info message.
@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin
# File lib/guard/ui.rb, line 50 def info(message, options = { }) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.info(message, plugin) end end
Get the Guard::UI logger instance
# File lib/guard/ui.rb, line 18 def logger @logger ||= begin options = self.options.dup Lumberjack::Logger.new(options.delete(:device) || $stderr, options) end end
Get the logger options
@return [Hash] the logger options
# File lib/guard/ui.rb, line 29 def options @options ||= { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } end
Set the logger options
@param [Hash] options the logger options @option options [Symbol] level the log level @option options [String] template the logger template @option options [String] time_format the time format
# File lib/guard/ui.rb, line 40 def options=(options) @options = options end
Reset a line.
# File lib/guard/ui.rb, line 112 def reset_line $stderr.print(color_enabled? ? "\r\e[0m" : "\r\n") end
Show a yellow warning message that is prefixed with WARNING.
@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin
# File lib/guard/ui.rb, line 63 def warning(message, options = { }) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.warn(color(message, :yellow), plugin) end end
Generated with the Darkfish Rdoc Generator 2.