Module: Guard::UI

Defined in:
lib/guard/ui.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 does some output that is piped into another process for further processing, please just write it to STDOUT with ‘puts`.

Constant Summary collapse

ANSI_ESCAPE_BRIGHT =

Brighten the color

'1'
ANSI_ESCAPE_BLACK =

Black foreground color

'30'
ANSI_ESCAPE_RED =

Red foreground color

'31'
ANSI_ESCAPE_GREEN =

Green foreground color

'32'
ANSI_ESCAPE_YELLOW =

Yellow foreground color

'33'
ANSI_ESCAPE_BLUE =

Blue foreground color

'34'
ANSI_ESCAPE_MAGENTA =

Magenta foreground color

'35'
ANSI_ESCAPE_CYAN =

Cyan foreground color

'36'
ANSI_ESCAPE_WHITE =

White foreground color

'37'
ANSI_ESCAPE_BGBLACK =

Black background color

'40'
ANSI_ESCAPE_BGRED =

Red background color

'41'
ANSI_ESCAPE_BGGREEN =

Green background color

'42'
ANSI_ESCAPE_BGYELLOW =

Yellow background color

'43'
ANSI_ESCAPE_BGBLUE =

Blue background color

'44'
ANSI_ESCAPE_BGMAGENTA =

Magenta background color

'45'
ANSI_ESCAPE_BGCYAN =

Cyan background color

'46'
ANSI_ESCAPE_BGWHITE =

White background color

'47'

Class Method Summary collapse

Class Method Details

.clearObject

Clear the output.



71
72
73
# File 'lib/guard/ui.rb', line 71

def clear
  system('clear;')
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



56
57
58
59
60
61
# File 'lib/guard/ui.rb', line 56

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[:debug]
  end
end

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

Show a red deprecation message that is prefixed with DEPRECATION.

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



44
45
46
47
48
49
# File 'lib/guard/ui.rb', line 44

def deprecation(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color('DEPRECATION: ', :red) + message
  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



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

def error(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color('ERROR: ', :red) + message
  end
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



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

def info(message, options = { })
  unless ENV['GUARD_ENV'] == 'test'
    reset_line if options[:reset]
    STDERR.puts color(message) if message != ''
  end
end

.reset_lineObject

Reset a line.



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

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