Module: Guard::UI

Includes:
Colors
Defined in:
lib/guard/ui.rb,
lib/guard/ui/colors.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

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

Class Method Details

.action_with_scopes(action, scope) ⇒ Object

Show a scoped action message.

Parameters:

  • action (String)

    the action to show

  • scopes (Hash)

    hash with a guard or a group scope



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

def action_with_scopes(action, scope)
  first_non_blank_scope = _first_non_blank_scope(scope)
  scope_message = first_non_blank_scope.map(&:title).join(', ') unless first_non_blank_scope.nil?

  info "#{ action } #{ scope_message || 'all' }"
end

.clear(options = {}) ⇒ Object

Clear the output if clearable.



106
107
108
109
110
111
# File 'lib/guard/ui.rb', line 106

def clear(options = {})
  if ::Guard.options[:clear] && (@clearable || options[:force])
    @clearable = false
    system('clear;')
  end
end

.clearableObject

Allow the screen to be cleared again.



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

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



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

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



84
85
86
# File 'lib/guard/ui.rb', line 84

def deprecation(message, options = {})
  warning(message, options) if ::Guard.options[:show_deprecations]
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



73
74
75
# File 'lib/guard/ui.rb', line 73

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



53
54
55
# File 'lib/guard/ui.rb', line 53

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

.loggerObject

Get the Guard::UI logger instance



22
23
24
25
26
# File 'lib/guard/ui.rb', line 22

def logger
  @logger ||= begin
    Lumberjack::Logger.new(options.fetch(:device) { $stderr }, options)
  end
end

.optionsHash

Get the logger options

Returns:

  • (Hash)

    the logger options



32
33
34
# File 'lib/guard/ui.rb', line 32

def options
  @options ||= ::Guard::Options.new(level: :info, template: ':time - :severity - :message', time_format: '%H:%M:%S')
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



43
44
45
# File 'lib/guard/ui.rb', line 43

def options=(options)
  @options = ::Guard::Options.new(options)
end

.reset_lineObject

Reset a line.



100
101
102
# File 'lib/guard/ui.rb', line 100

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



63
64
65
# File 'lib/guard/ui.rb', line 63

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