In Files

Files

Guard::UI

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`.

Constants

ANSI_ESCAPE_BGBLACK

Black background color

ANSI_ESCAPE_BGBLUE

Blue background color

ANSI_ESCAPE_BGCYAN

Cyan background color

ANSI_ESCAPE_BGGREEN

Green background color

ANSI_ESCAPE_BGMAGENTA

Magenta background color

ANSI_ESCAPE_BGRED

Red background color

ANSI_ESCAPE_BGWHITE

White background color

ANSI_ESCAPE_BGYELLOW

Yellow background color

ANSI_ESCAPE_BLACK

Black foreground color

ANSI_ESCAPE_BLUE

Blue foreground color

ANSI_ESCAPE_BRIGHT

Brighten the color

ANSI_ESCAPE_CYAN

Cyan foreground color

ANSI_ESCAPE_GREEN

Green foreground color

ANSI_ESCAPE_MAGENTA

Magenta foreground color

ANSI_ESCAPE_RED

Red foreground color

ANSI_ESCAPE_WHITE

White foreground color

ANSI_ESCAPE_YELLOW

Yellow foreground color

Public Class Methods

action_with_scopes(action, scopes) click to toggle source

Show a scoped action message.

@param [String] action the action to show @param [Hash] scopes hash with a guard or a group scope

# File lib/guard/ui.rb, line 136
def action_with_scopes(action, scopes)
  plugins = scopes[:plugins] || []
  groups  = scopes[:groups] || []

  if plugins.empty? && groups.empty?
    plugins = ::Guard.scope[:plugins] || []
    groups  = ::Guard.scope[:groups] || []
  end

  scope_message ||= plugins.join(',') unless plugins.empty?
  scope_message ||= groups.join(',') unless groups.empty?
  scope_message ||= 'all'

  info "#{ action } #{ scope_message }"
end
clear(options = {}) click to toggle source

Clear the output if clearable.

# File lib/guard/ui.rb, line 118
def clear(options = {})
  if ::Guard.options[:clear] && (@clearable || options[:force])
    @clearable = false
    system('clear;')
  end
end
clearable() click to toggle source

Allow the screen to be cleared again.

# File lib/guard/ui.rb, line 127
def clearable
  @clearable = true
end
debug(message, options = { }) click to toggle source

Show a debug message that is prefixed with DEBUG and a timestamp.

@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin

# File lib/guard/ui.rb, line 103
def debug(message, options = { })
  filter(options[:plugin]) do |plugin|
    reset_line if options[:reset]
    self.logger.debug(color(message, :yellow), plugin)
  end
end
deprecation(message, options = { }) click to toggle source

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

@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin

# File lib/guard/ui.rb, line 90
def deprecation(message, options = { })
  filter(options[:plugin]) do |plugin|
    reset_line if options[:reset]
    self.logger.warn(color(message, :yellow), plugin)
  end
end
error(message, options = { }) click to toggle source

Show a red error message that is prefixed with ERROR.

@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin

# File lib/guard/ui.rb, line 76
def error(message, options = { })
  filter(options[:plugin]) do |plugin|
    reset_line if options[:reset]
    self.logger.error(color(message, :red), plugin)
  end
end
info(message, options = { }) click to toggle source

Show an info message.

@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin

# File lib/guard/ui.rb, line 50
def info(message, options = { })
  filter(options[:plugin]) do |plugin|
    reset_line if options[:reset]
    self.logger.info(message, plugin)
  end
end
logger() click to toggle source

Get the Guard::UI logger instance

# File lib/guard/ui.rb, line 18
def logger
  @logger ||= begin
    options = self.options.dup
    Lumberjack::Logger.new(options.delete(:device) || $stderr, options)
  end
end
options() click to toggle source

Get the logger options

@return [Hash] the logger options

# File lib/guard/ui.rb, line 29
def options
  @options ||= { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' }
end
options=(options) click to toggle source

Set the logger options

@param [Hash] options the logger options @option options [Symbol] level the log level @option options [String] template the logger template @option options [String] time_format the time format

# File lib/guard/ui.rb, line 40
def options=(options)
  @options = options
end
reset_line() click to toggle source

Reset a line.

# File lib/guard/ui.rb, line 112
def reset_line
  $stderr.print(color_enabled? ? "\r\e[0m" : "\r\n")
end
warning(message, options = { }) click to toggle source

Show a yellow warning message that is prefixed with WARNING.

@param [String] message the message to show @option options [Boolean] reset whether to clean the output before @option options [String] plugin manually define the calling plugin

# File lib/guard/ui.rb, line 63
def warning(message, options = { })
  filter(options[:plugin]) do |plugin|
    reset_line if options[:reset]
    self.logger.warn(color(message, :yellow), plugin)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.