Module: Simple::UI
Constant Summary collapse
- VERSION =
"0.3.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
- #benchmark(msg, *args, &block) ⇒ Object
- #debug(msg, *args) ⇒ Object
- #error(msg, *args) ⇒ Object
- #info(msg, *args) ⇒ Object
- #success(msg, *args) ⇒ Object
- #warn(msg, *args) ⇒ Object
Class Method Details
.colored=(colored) ⇒ Object
95 96 97 |
# File 'lib/simple/ui.rb', line 95 def self.colored=(colored) @colored = colored end |
.colored? ⇒ Boolean
99 100 101 102 103 104 105 |
# File 'lib/simple/ui.rb', line 99 def self.colored? if @colored.nil? @colored = STDERR.tty? end @colored != false end |
.verbosity ⇒ Object
9 10 11 |
# File 'lib/simple/ui.rb', line 9 def self.verbosity @verbosity ||= 1 end |
.verbosity=(verbosity) ⇒ Object
13 14 15 |
# File 'lib/simple/ui.rb', line 13 def self.verbosity=(verbosity) @verbosity = verbosity end |
Instance Method Details
#benchmark(msg, *args, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/simple/ui.rb', line 76 def benchmark(msg, *args, &block) severity = :warn if msg.is_a?(Symbol) severity, msg = msg, args.shift end start = Time.now r = yield msg += ": #{(1000 * (Time.now - start)).to_i} msecs." Simple::UI.log severity, msg, *args r rescue StandardError msg += "raises #{$!.class.name} after #{(1000 * (Time.now - start)).to_i} msecs." Simple::UI.log severity, msg, *args raise $! end |
#debug(msg, *args) ⇒ Object
56 57 58 |
# File 'lib/simple/ui.rb', line 56 def debug(msg, *args) Simple::UI.log :debug, msg, *args end |
#error(msg, *args) ⇒ Object
68 69 70 |
# File 'lib/simple/ui.rb', line 68 def error(msg, *args) Simple::UI.log :error, msg, *args end |
#info(msg, *args) ⇒ Object
60 61 62 |
# File 'lib/simple/ui.rb', line 60 def info(msg, *args) Simple::UI.log :info, msg, *args end |