Module: Massimo::UI
Constant Summary collapse
- COLOR_CODES =
{ :black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36 }.freeze
Instance Method Summary collapse
-
#color(message, color) ⇒ Object
Color the given message with the given color.
-
#indent(amount = 2) ⇒ Object
Indents the messages within the block by the given amount.
-
#report_errors ⇒ Object
Run the given block and cleanly report any errors.
-
#say(message, *args) ⇒ Object
Say (print) something to the user.
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(, color) "\e[#{COLOR_CODES[color.to_sym]}m#{}\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_errors ⇒ Object
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., :magenta say error.backtrace.first, :magenta end growl "#{error.}\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(, *args) = args. color = args.first growl() if [:growl] = (' ' * padding) + .to_s = self.color(, color) if color $stdout.puts() end |