module Guard::UI
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 |plugin| reset_line if options[:reset] logger.send(method, message, plugin) 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 calling_plugin_name(depth = 2)
-
(String)- the Guard plugin name
Parameters:
-
depth(Integer) -- the stack depth
def calling_plugin_name(depth = 2) name = /(guard\/[a-z_]*)(\/[a-z_]*)?.rb:/i.match(caller[depth]) return "Guard" unless name name[1].split("/").map do |part| part.split(/[^a-z0-9]/i).map(&:capitalize).join end.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 if @color_enabled.nil? if Gem.win_platform? if ENV["ANSICON"] @color_enabled = true else begin require "rubygems" unless ENV["NO_RUBYGEMS"] require "Win32/Console/ANSI" @color_enabled = true rescue LoadError @color_enabled = false info "Run 'gem install win32console' to use color on Windows" end end else @color_enabled = true end end @color_enabled 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) logger.level = new_level end
def logger
Get the Guard::UI logger instance
def logger @logger ||= begin require "lumberjack" Lumberjack::Logger.new( options.fetch(:device) { $stderr }, options) end end
def options
-
(Hash)- the logger options
def options @options ||= Options.new( level: :info, template: ":time - :severity - :message", time_format: "%H:%M:%S") 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 = Options.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