Module: Guard::UI
- Defined in:
- lib/guard/ui.rb,
lib/guard/ui/colors.rb,
lib/guard/ui/config.rb,
lib/guard/ui/logger_config.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
.
Class Method Summary collapse
-
.action_with_scopes(action, titles) ⇒ 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.
-
.options=(options) ⇒ Object
Set the logger options.
-
.reset_line ⇒ Object
Reset a line.
-
.warning(message, options = {}) ⇒ Object
Show a yellow warning message that is prefixed with WARNING.
Class Method Details
.action_with_scopes(action, titles) ⇒ Object
Show a scoped action message.
186 187 188 |
# File 'lib/guard/ui.rb', line 186 def action_with_scopes(action, titles) info "#{action} #{titles.join(', ')}" end |
.clear(opts = {}) ⇒ Object
Clear the output if clearable.
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/guard/ui.rb', line 156 def clear(opts = {}) return unless engine return unless engine.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.
177 178 179 |
# File 'lib/guard/ui.rb', line 177 def clearable! @clearable = true end |
.debug(message, options = {}) ⇒ Object
Show a debug message that is prefixed with DEBUG and a timestamp.
139 140 141 |
# File 'lib/guard/ui.rb', line 139 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
.
125 126 127 128 129 130 131 |
# File 'lib/guard/ui.rb', line 125 def deprecation(, = {}) unless ENV["GUARD_GEM_SILENCE_DEPRECATIONS"] == "1" backtrace = Thread.current.backtrace[1..5].join("\n\t >") msg = format("%<message>s\nDeprecation backtrace: %<backtrace>s", message: , backtrace: backtrace) warning(msg, ) end end |
.error(message, options = {}) ⇒ Object
Show a red error message that is prefixed with ERROR.
114 115 116 |
# File 'lib/guard/ui.rb', line 114 def error(, = {}) (, :error, :red, ) end |
.info(message, options = {}) ⇒ Object
Show an info message.
94 95 96 |
# File 'lib/guard/ui.rb', line 94 def info(, = {}) (, :info, nil, ) end |
.options=(options) ⇒ Object
Set the logger options
65 66 67 |
# File 'lib/guard/ui.rb', line 65 def () @options = Config.new() end |
.reset_line ⇒ Object
Reset a line.
145 146 147 |
# File 'lib/guard/ui.rb', line 145 def reset_line $stderr.print(color_enabled? ? "\r\e[0m" : "\r\n") end |
.warning(message, options = {}) ⇒ Object
Show a yellow warning message that is prefixed with WARNING.
104 105 106 |
# File 'lib/guard/ui.rb', line 104 def warning(, = {}) (, :warn, :yellow, ) end |