Module: UI

Extended by:
UI
Included in:
UI
Defined in:
lib/simple/ui.rb

Constant Summary collapse

VERSION =
"0.2.0"
COLORS =
{
  clear:      "\e[0m",  # Embed in a String to clear all previous ANSI sequences.
  bold:       "\e[1m",  # The start of an ANSI bold sequence.
  black:      "\e[30m", # Set the terminal's foreground ANSI color to black.
  red:        "\e[31m", # Set the terminal's foreground ANSI color to red.
  green:      "\e[32m", # Set the terminal's foreground ANSI color to green.
  yellow:     "\e[33m", # Set the terminal's foreground ANSI color to yellow.
  blue:       "\e[34m", # Set the terminal's foreground ANSI color to blue.
  magenta:    "\e[35m", # Set the terminal's foreground ANSI color to magenta.
  cyan:       "\e[36m", # Set the terminal's foreground ANSI color to cyan.
  white:      "\e[37m", # Set the terminal's foreground ANSI color to white.

  on_black:   "\e[40m", # Set the terminal's background ANSI color to black.
  on_red:     "\e[41m", # Set the terminal's background ANSI color to red.
  on_green:   "\e[42m", # Set the terminal's background ANSI color to green.
  on_yellow:  "\e[43m", # Set the terminal's background ANSI color to yellow.
  on_blue:    "\e[44m", # Set the terminal's background ANSI color to blue.
  on_magenta: "\e[45m", # Set the terminal's background ANSI color to magenta.
  on_cyan:    "\e[46m", # Set the terminal's background ANSI color to cyan.
  on_white:   "\e[47m"  # Set the terminal's background ANSI color to white.
}
MESSAGE_COLOR =
{
  :info     => :cyan,
  :warn     => :yellow,
  :error    => :red,
  :success  => :green,
}
MIN_VERBOSITY =
{
  :debug    => 3,
  :info     => 2,
  :warn     => 1,
  :error    => 0,
  :success  => 0
}
@@started_at =
Time.now

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.verbosityObject



6
7
8
# File 'lib/simple/ui.rb', line 6

def self.verbosity
  @verbosity ||= 1
end

.verbosity=(verbosity) ⇒ Object



10
11
12
# File 'lib/simple/ui.rb', line 10

def self.verbosity=(verbosity)
  @verbosity = verbosity
end

Instance Method Details

#benchmark(msg, *args, &block) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/simple/ui.rb', line 73

def benchmark(msg, *args, &block)
  severity = :warn
  if msg.is_a?(Symbol)
    severity, msg = msg, args.shift
  end
  
  start = Time.now
  yield.tap do
    msg += ": #{(1000 * (Time.now - start)).to_i} msecs."
    UI.log severity, msg, *args
  end
end

#debug(msg, *args) ⇒ Object



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

def debug(msg, *args)
  UI.log :debug, msg, *args
end

#error(msg, *args) ⇒ Object



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

def error(msg, *args)
  UI.log :error, msg, *args
end

#info(msg, *args) ⇒ Object



57
58
59
# File 'lib/simple/ui.rb', line 57

def info(msg, *args)
  UI.log :info, msg, *args
end

#success(msg, *args) ⇒ Object



69
70
71
# File 'lib/simple/ui.rb', line 69

def success(msg, *args)
  UI.log :success, msg, *args
end

#warn(msg, *args) ⇒ Object



61
62
63
# File 'lib/simple/ui.rb', line 61

def warn(msg, *args)
  UI.log :warn, msg, *args
end