Created
February 16, 2013 04:06
-
-
Save jewel12/4965489 to your computer and use it in GitHub Desktop.
requireすると標準出力がJewelve.comっぽくなるオモシロrbです
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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