Module: Massimo::UI

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

Constant Summary collapse

COLOR_CODES =
{
  :black   => 30,
  :red     => 31,
  :green   => 32,
  :yellow  => 33,
  :blue    => 34,
  :magenta => 35,
  :cyan    => 36
}.freeze

Instance Method Summary collapse

Instance Method Details

#color(message, color) ⇒ Object

Color the given message with the given color



30
31
32
# File 'lib/massimo/ui.rb', line 30

def color(message, color)
  "\e[#{COLOR_CODES[color.to_sym]}m#{message}\e[0m"
end

#indent(amount = 2) ⇒ Object

Indents the messages within the block by the given amount.



51
52
53
54
55
# File 'lib/massimo/ui.rb', line 51

def indent(amount = 2)
  self.padding += amount
  yield
  self.padding -= amount
end

#report_errorsObject

Run the given block and cleanly report any errors



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/massimo/ui.rb', line 35

def report_errors
  begin
    yield
    true
  rescue Exception => error
    say 'massimo had a problem', :red
    indent do
      say error.message, :magenta
      say error.backtrace.first, :magenta
    end
    growl "#{error.message}\n#{error.backtrace.first}", 'massimo problem'
    false
  end
end

#say(message, *args) ⇒ Object

Say (print) something to the user.



18
19
20
21
22
23
24
25
26
27
# File 'lib/massimo/ui.rb', line 18

def say(message, *args)
  options = args.extract_options!
  color   = args.first
  
  growl(message) if options[:growl]
  message = (' ' * padding) + message.to_s
  message = self.color(message, color) if color

  $stdout.puts(message)
end