lib/poolpartycl.rb in auser-poolparty-1.2.0 vs lib/poolpartycl.rb in auser-poolparty-1.2.1
- old
+ new
@@ -4,9 +4,60 @@
def help_array
["-h", "--help", "-V", "--version", "--debug", "-d"]
end
+def ask_with_help(opts={}, &block)
+ help_str = opts[:help]
+ message = opts[:message]
+
+ o = ask("#{message} (h for help)") do |q|
+ q.validate = opts[:validate] if opts.has_key?(:validate)
+ end
+
+ if %w(h H).include?(o)
+ colored_say help_str, :help
+ ask_with_help(opts, &block)
+ else
+ block.call(o)
+ end
+ o
+end
+
+def rescued_ask(m, r)
+ begin
+ t = colored_ask m
+ rescue Exception => e
+ say r
+ end
+end
+
+def colored_ask(str, color = :notice)
+ setup_colors
+ ask("<%= color(\"#{str}\", :#{color}) %>")
+end
+
+def colored_say(str, color = :headline)
+ setup_colors
+ say("<%= color(\"#{str}\", :#{color}) %>")
+end
+
+def setup_colors
+ unless @setup_colors
+ ft = HighLine::ColorScheme.new do |cs|
+ cs[:headline] = [ :bold, :yellow, :on_black ]
+ cs[:horizontal_line] = [ :bold, :white, :on_blue]
+ cs[:critical] = [ :yellow, :on_red ]
+ cs[:error] = [ :bold, :red ]
+ cs[:help] = [ :bold, :white, :on_blue]
+ cs[:notice] = [ :blue, :on_white]
+ end
+
+ HighLine.color_scheme = ft
+ @setup_colors = true
+ end
+end
+
def are_you_sure?(msg)
puts msg
resp = gets.strip!
case resp
\ No newline at end of file