summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2018-03-06 19:11:17 -0700
committermokha <mokha@cisco.com>2018-03-06 19:11:17 -0700
commit6c5d043ea86bcae39aa806e53625f55bd5a6bf03 (patch)
tree948c3682199126228351c4328261b1b34c717012 /lib
parent64055d426ed749165770814ee1329585fdff15f2 (diff)
add rainbow command.
Diffstat (limited to 'lib')
-rw-r--r--lib/xsay.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/xsay.rb b/lib/xsay.rb
index 1623008..00f769b 100644
--- a/lib/xsay.rb
+++ b/lib/xsay.rb
@@ -1,5 +1,6 @@
require "xsay/version"
require "thor"
+require "colorize"
module Xsay
class CLI < Thor
@@ -23,21 +24,33 @@ module Xsay
desc "random <message>", "xsay random hello"
def random(*args)
- render(args, IO.read(ANIMALS.shuffle.sample))
+ render(args, IO.read(ANIMALS.shuffle.sample), colour: String.colors.sample)
+ end
+
+ desc "rainbow <message>", "xsay rainbow hello world"
+ def rainbow(*args)
+ render(args, IO.read(ANIMALS.shuffle.sample), colour: :rainbow)
end
private
- def render(message, template)
+ def render(message, template, colour: :default)
message = message.join(' ') if message.respond_to?(:join)
line_break = "-" * message.length
- say <<-MESSAGE
+ result = <<-MESSAGE
#{line_break}
< #{message} >
#{line_break}
#{template}
MESSAGE
+ if colour == :rainbow
+ result.each_char.each_with_index do |x, i|
+ print x.colorize(String.colors[i % String.colors.size])
+ end
+ else
+ puts result.colorize(colour)
+ end
end
end
end