Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Forked from jewel12/Jewelve.rb
Created February 16, 2013 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shinpeim/4965540 to your computer and use it in GitHub Desktop.
Save Shinpeim/4965540 to your computer and use it in GitHub Desktop.
# -*- 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