module Guard::UI

def clear


Clear the output.
def clear
  system('clear;')
end

def color(text, *color_options)

Parameters:
  • color_options (Array) -- the color options
  • text (String) -- the text to colorize
def color(text, *color_options)
  color_code = ''
  color_options.each do |color_option|
    color_option = color_option.to_s
    if color_option != ''
      if !(color_option =~ /\d+/)
        color_option = const_get("ANSI_ESCAPE_#{ color_option.upcase }")
      end
      color_code += ';' + color_option
    end
  end
  color_enabled? ? "\e[0#{ color_code }m#{ text }\e[0m" : text
end

def color_enabled?

Returns:
  • (Boolean) - whether color is enabled or not
def color_enabled?
  if @color_enabled.nil?
    if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
      if ENV['ANSICON']
        @color_enabled = true
      else
        begin
          require 'rubygems' unless ENV['NO_RUBYGEMS']
          require 'Win32/Console/ANSI'
          @color_enabled = true
        rescue LoadError
          @color_enabled = false
          info "You must 'gem install win32console' to use color on Windows"
        end
      end
    else
      @color_enabled = true
    end
  end
  @color_enabled
end

def debug(message, options = { })

Options Hash: (**options)
  • reset (Boolean) -- whether to clean the output before

Parameters:
  • message (String) -- the message to show
def debug(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color("DEBUG (#{Time.now.strftime('%T')}): ", :yellow) + message if ::Guard.options && ::Guard.options[:verbose]
  end
end

def deprecation(message, options = { })

Options Hash: (**options)
  • reset (Boolean) -- whether to clean the output before

Parameters:
  • message (String) -- the message to show
def deprecation(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color('DEPRECATION: ', :red) + message
  end
end

def error(message, options = { })

Options Hash: (**options)
  • reset (Boolean) -- whether to clean the output before

Parameters:
  • message (String) -- the message to show
def error(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color('ERROR: ', :red) + message
  end
end

def info(message, options = { })

Options Hash: (**options)
  • reset (Boolean) -- whether to clean the output before

Parameters:
  • message (String) -- the message to show
def info(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color(message) if message != ''
  end
end

def reset_color(text)

Parameters:
  • text (String) -- the text

Deprecated:
def reset_color(text)
  deprecation('UI.reset_color(text) is deprecated, please use color(text, ' ') instead.')
  color(text, '')
end

def reset_line


Reset a line.
def reset_line
  STDERR.print(color_enabled? ? "\r\e[0m" : "\r\n")
end

def warning(message, options = { })

Options Hash: (**options)
  • reset (Boolean) -- whether to clean the output before

Parameters:
  • message (String) -- the message to show
def warning(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color('WARNING: ', :yellow) + message
  end
end