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

Class Method Details

.action_with_scopes(action, titles) ⇒ Object

Show a scoped action message.

Parameters:

  • action (String)

    the action to show

  • scope (Hash)

    hash with a guard or a group scope



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.

Parameters:

  • message (String)

    the message to show

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • reset (Boolean)

    whether to clean the output before

  • plugin (String)

    manually define the calling plugin



139
140
141
# File 'lib/guard/ui.rb', line 139

def debug(message, options = {})
  _filtered_logger_message(message, :debug, :yellow, options)
end

.deprecation(message, options = {}) ⇒ Object

Show a red deprecation message that is prefixed with DEPRECATION. It has a log level of warn.

Parameters:

  • message (String)

    the message to show

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • reset (Boolean)

    whether to clean the output before

  • plugin (String)

    manually define the calling plugin



125
126
127
128
129
130
131
# File 'lib/guard/ui.rb', line 125

def deprecation(message, options = {})
  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: message, backtrace: backtrace)
    warning(msg, options)
  end
end

.error(message, options = {}) ⇒ Object

Show a red error message that is prefixed with ERROR.

Parameters:

  • message (String)

    the message to show

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • reset (Boolean)

    whether to clean the output before

  • plugin (String)

    manually define the calling plugin



114
115
116
# File 'lib/guard/ui.rb', line 114

def error(message, options = {})
  _filtered_logger_message(message, :error, :red, options)
end

.info(message, options = {}) ⇒ Object

Show an info message.

Parameters:

  • message (String)

    the message to show

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • reset (Boolean)

    whether to clean the output before

  • plugin (String)

    manually define the calling plugin



94
95
96
# File 'lib/guard/ui.rb', line 94

def info(message, options = {})
  _filtered_logger_message(message, :info, nil, options)
end

.options=(options) ⇒ Object

Set the logger options

Parameters:

  • options (Hash)

    the logger options

Options Hash (options):

  • level (Symbol)

    the log level

  • template (String)

    the logger template

  • time_format (String)

    the time format



65
66
67
# File 'lib/guard/ui.rb', line 65

def options=(options)
  @options = Config.new(options)
end

.reset_lineObject

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.

Parameters:

  • message (String)

    the message to show

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • reset (Boolean)

    whether to clean the output before

  • plugin (String)

    manually define the calling plugin



104
105
106
# File 'lib/guard/ui.rb', line 104

def warning(message, options = {})
  _filtered_logger_message(message, :warn, :yellow, options)
end