Module: Guard::UI
- Includes:
- Colors
- Defined in:
- lib/guard/ui.rb,
lib/guard/ui/colors.rb,
lib/guard/ui/config.rb,
lib/guard/ui/logger.rb
Overview
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`.
Defined Under Namespace
Modules: Colors Classes: Config, Logger
Constant Summary
Constants included from Colors
Colors::ANSI_ESCAPE_BGBLACK, Colors::ANSI_ESCAPE_BGBLUE, Colors::ANSI_ESCAPE_BGCYAN, Colors::ANSI_ESCAPE_BGGREEN, Colors::ANSI_ESCAPE_BGMAGENTA, Colors::ANSI_ESCAPE_BGRED, Colors::ANSI_ESCAPE_BGWHITE, Colors::ANSI_ESCAPE_BGYELLOW, Colors::ANSI_ESCAPE_BLACK, Colors::ANSI_ESCAPE_BLUE, Colors::ANSI_ESCAPE_BRIGHT, Colors::ANSI_ESCAPE_CYAN, Colors::ANSI_ESCAPE_GREEN, Colors::ANSI_ESCAPE_MAGENTA, Colors::ANSI_ESCAPE_RED, Colors::ANSI_ESCAPE_WHITE, Colors::ANSI_ESCAPE_YELLOW
Class Method Summary collapse
-
.action_with_scopes(action, scope) ⇒ Object
Show a scoped action message.
-
.clear(opts = {}) ⇒ Object
Clear the output if clearable.
-
.clearable ⇒ Object
Allow the screen to be cleared again.
-
.debug(message, options = {}) ⇒ Object
Show a debug message that is prefixed with DEBUG and a timestamp.
-
.deprecation(message, options = {}) ⇒ Object
Show a red deprecation message that is prefixed with DEPRECATION.
-
.error(message, options = {}) ⇒ Object
Show a red error message that is prefixed with ERROR.
-
.info(message, options = {}) ⇒ Object
Show an info message.
-
.level=(new_level) ⇒ Object
Assigns a log level.
-
.logger ⇒ Object
Get the Guard::UI logger instance.
-
.options ⇒ Hash
Get the logger options.
-
.options=(options) ⇒ Object
Set the logger options.
-
.reset_and_clear ⇒ Object
TODO: arguments: UI uses Guard::options anyway.
-
.reset_line ⇒ Object
Reset a line.
-
.reset_logger ⇒ Object
Since logger is global, for Aruba in-process to properly separate output between calls, we need to reset.
-
.warning(message, options = {}) ⇒ Object
Show a yellow warning message that is prefixed with WARNING.
Class Method Details
.action_with_scopes(action, scope) ⇒ Object
Show a scoped action message.
161 162 163 164 |
# File 'lib/guard/ui.rb', line 161 def action_with_scopes(action, scope) titles = Guard.state.scope.titles(scope) info "#{action} #{titles.join(', ')}" end |
.clear(opts = {}) ⇒ Object
Clear the output if clearable.
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/guard/ui.rb', line 131 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 |
.clearable ⇒ Object
Allow the screen to be cleared again.
152 153 154 |
# File 'lib/guard/ui.rb', line 152 def clearable @clearable = true end |
.debug(message, options = {}) ⇒ Object
Show a debug message that is prefixed with DEBUG and a timestamp.
119 120 121 |
# File 'lib/guard/ui.rb', line 119 def debug(, = {}) (, :debug, :yellow, ) end |
.deprecation(message, options = {}) ⇒ Object
Show a red deprecation message that is prefixed with DEPRECATION. It has a log level of ‘warn`.
105 106 107 108 109 110 111 |
# File 'lib/guard/ui.rb', line 105 def deprecation(, = {}) unless ENV["GUARD_GEM_SILENCE_DEPRECATIONS"] == "1" backtrace = Thread.current.backtrace[1..5].join("\n\t >") msg = format("%s\nDeprecation backtrace: %s", , backtrace) warning(msg, ) end end |
.error(message, options = {}) ⇒ Object
Show a red error message that is prefixed with ERROR.
94 95 96 |
# File 'lib/guard/ui.rb', line 94 def error(, = {}) (, :error, :red, ) end |
.info(message, options = {}) ⇒ Object
Show an info message.
74 75 76 |
# File 'lib/guard/ui.rb', line 74 def info(, = {}) (, :info, nil, ) end |
.level=(new_level) ⇒ Object
Assigns a log level
63 64 65 66 |
# File 'lib/guard/ui.rb', line 63 def level=(new_level) .logger_config.level = new_level @logger.level = new_level if @logger end |
.logger ⇒ Object
Get the Guard::UI logger instance
26 27 28 29 30 31 32 |
# File 'lib/guard/ui.rb', line 26 def logger @logger ||= begin require "lumberjack" Lumberjack::Logger.new(.device, .logger_config) end end |
.options ⇒ Hash
Get the logger options
46 47 48 |
# File 'lib/guard/ui.rb', line 46 def @options ||= Config.new end |
.options=(options) ⇒ Object
Set the logger options
TODO: deprecate?
58 59 60 |
# File 'lib/guard/ui.rb', line 58 def () @options = Config.new() end |
.reset_and_clear ⇒ Object
TODO: arguments: UI uses Guard::options anyway
145 146 147 148 |
# File 'lib/guard/ui.rb', line 145 def reset_and_clear @clearable = false clear(force: true) end |
.reset_line ⇒ Object
Reset a line.
125 126 127 |
# File 'lib/guard/ui.rb', line 125 def reset_line $stderr.print(color_enabled? ? "\r\e[0m" : "\r\n") end |
.reset_logger ⇒ Object
Since logger is global, for Aruba in-process to properly separate output between calls, we need to reset
We don’t use logger=() since it’s expected to be a Lumberjack instance
38 39 40 |
# File 'lib/guard/ui.rb', line 38 def reset_logger @logger = nil end |
.warning(message, options = {}) ⇒ Object
Show a yellow warning message that is prefixed with WARNING.
84 85 86 |
# File 'lib/guard/ui.rb', line 84 def warning(, = {}) (, :warn, :yellow, ) end |