module Guard::UI
def _calling_plugin_name
-
(String)
- the Guard plugin name
Parameters:
-
depth
(Integer
) -- the stack depth
def _calling_plugin_name name = caller.lazy.map do |line| %r{(?<!guard\/lib)\/(guard\/[a-z_]*)(/[a-z_]*)?.rb:}i.match(line) end.reject(&:nil?).take(1).force.first return "Guard" unless name || (name && name[1] == "guard/lib") name[1].split("/").map do |part| part.split(/[^a-z0-9]/i).map(&:capitalize).join end.join("::") end
def _filter(plugin)
- Yieldparam: param - the calling plugin name
Other tags:
- Yield: - When the message should be logged
Parameters:
-
plugin
(String
) -- the calling plugin name
def _filter(plugin) only = options.only except = options.except plugin ||= _calling_plugin_name match = !(only || except) match ||= (only && only.match(plugin)) match ||= (except && !except.match(plugin)) return unless match yield plugin end
def _filtered_logger_message(message, method, color_name, options = {})
- Private: -
def _filtered_logger_message(message, method, color_name, options = {}) message = color(message, color_name) if color_name _filter(options[:plugin]) do reset_line if options[:reset] logger.send(method, message) end end
def action_with_scopes(action, scope)
-
scope
(Hash
) -- hash with a guard or a group scope -
action
(String
) -- the action to show
def action_with_scopes(action, scope) titles = Guard.state.scope.titles(scope) info "#{action} #{titles.join(', ')}" end
def clear(opts = {})
Clear the output if clearable.
def clear(opts = {}) return unless Guard.state.session.clear? fail "UI not set up!" if @clearable.nil? return unless @clearable || opts[:force] @clearable = false Terminal.clear rescue Errno::ENOENT => e warning("Failed to clear the screen: #{e.inspect}") end
def clearable
Allow the screen to be cleared again.
def clearable @clearable = true end
def color(text, *color_options)
-
color_options
(Array
) -- the color options -
text
(String
) -- the text to colorize
def color(text, *color_options) color_code = "" color_options.each do |color_option| color_option = color_option.to_s next if color_option == "" unless color_option =~ /\d+/ color_option = const_get("ANSI_ESCAPE_#{ color_option.upcase }") end color_code += ";" + color_option end color_enabled? ? "\e[0#{ color_code }m#{ text }\e[0m" : text end
def color_enabled?
-
(Boolean)
- whether color is enabled or not
def color_enabled? @color_enabled_initialized ||= false @color_enabled = nil unless @color_enabled_initialized @color_enabled_initialized = true return @color_enabled unless @color_enabled.nil? return (@color_enabled = true) unless Gem.win_platform? return (@color_enabled = true) if ENV["ANSICON"] @color_enabled = begin require "rubygems" unless ENV["NO_RUBYGEMS"] require "Win32/Console/ANSI" true rescue LoadError info "Run 'gem install win32console' to use color on Windows" false end end
def debug(message, options = {})
(**options)
-
plugin
(String
) -- manually define the calling plugin -
reset
(Boolean
) -- whether to clean the output before
Parameters:
-
message
(String
) -- the message to show
def debug(message, options = {}) _filtered_logger_message(message, :debug, :yellow, options) end
def deprecation(message, options = {})
(**options)
-
plugin
(String
) -- manually define the calling plugin -
reset
(Boolean
) -- whether to clean the output before
Parameters:
-
message
(String
) -- the message to show
def deprecation(message, options = {}) unless ENV["GUARD_GEM_SILENCE_DEPRECATIONS"] == "1" backtrace = Thread.current.backtrace[1..5].join("\n\t >") msg = format("%s\nDeprecation backtrace: %s", message, backtrace) warning(msg, options) end end
def error(message, options = {})
(**options)
-
plugin
(String
) -- manually define the calling plugin -
reset
(Boolean
) -- whether to clean the output before
Parameters:
-
message
(String
) -- the message to show
def error(message, options = {}) _filtered_logger_message(message, :error, :red, options) end
def info(message, options = {})
(**options)
-
plugin
(String
) -- manually define the calling plugin -
reset
(Boolean
) -- whether to clean the output before
Parameters:
-
message
(String
) -- the message to show
def info(message, options = {}) _filtered_logger_message(message, :info, nil, options) end
def level=(new_level)
def level=(new_level) options.logger_config.level = new_level @logger.level = new_level if @logger end
def logger
Get the Guard::UI logger instance
def logger @logger ||= begin require "lumberjack" Lumberjack::Logger.new(options.device, options.logger_config) end end
def options
-
(Hash)
- the logger options
def options @options ||= Config.new end
def options=(options)
(**options)
-
time_format
(String
) -- the time format -
template
(String
) -- the logger template -
level
(Symbol
) -- the log level
Parameters:
-
options
(Hash
) -- the logger options
def options=(options) @options = Config.new(options) end
def reset_and_clear
- Private: - api
def reset_and_clear @clearable = false clear(force: true) end
def reset_line
Reset a line.
def reset_line $stderr.print(color_enabled? ? "\r\e[0m" : "\r\n") end
def reset_logger
separate output between calls, we need to reset
Since logger is global, for Aruba in-process to properly
def reset_logger @logger = nil end
def warning(message, options = {})
(**options)
-
plugin
(String
) -- manually define the calling plugin -
reset
(Boolean
) -- whether to clean the output before
Parameters:
-
message
(String
) -- the message to show
def warning(message, options = {}) _filtered_logger_message(message, :warn, :yellow, options) end