Skip to content

Instantly share code, notes, and snippets.

@jewel12
Created February 16, 2013 04:06
Show Gist options
  • Save jewel12/4965489 to your computer and use it in GitHub Desktop.
Save jewel12/4965489 to your computer and use it in GitHub Desktop.
requireすると標準出力がJewelve.comっぽくなるオモシロrbです
# -*- coding: utf-8 -*-
module StringsOfJewelve
COLOR_NUMBERS = (0..7).to_a
def to_jewelve
return self.split('').map(&:to_random_colored).shuffle.join
end
def to_random_colored
fg_color, bg_color = select_fg_bg_colors
return "\e[7;3#{fg_color};4#{bg_color}m" + self + "\e[m"
end
def to_default_colored
return "\e[39;49m" + self + "\e[m"
end
private
def select_fg_bg_colors
return COLOR_NUMBERS.sample(2)
end
end
module JewelveIOExtention
SPECIAL_MARKERS = (0..31)
def write(str)
if str.bytes.any? {|c| SPECIAL_MARKERS.include?(c)}
super str
else
10.times do
sleep(0.1)
super "\e[s"
super str.to_jewelve
super "\e[u"
end
super str.to_default_colored
end
end
end
String.send(:include, StringsOfJewelve)
$stdout.extend(JewelveIOExtention)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment