1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

corrections to tests-hash is :pale so color code should be normal(0)-white(7), add some constants to make the code readable

(cherry picked from commit dbd453297c9fff47dc06845cdc5685ffb58b114e)
This commit is contained in:
Michael Mullis 2010-05-11 12:53:19 -04:00 committed by Mike Dvorkin
parent 92dfe6df04
commit ed177c0b10
3 changed files with 19 additions and 13 deletions

View file

@ -4,11 +4,15 @@
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class String
ANSI_ESCAPE = "\033"
ANSI_COLOR_BASE = 30
ANSI_BRIGHT = 1
ANSI_NORMAL = 0
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
if STDOUT.tty? && ENV['TERM'] && ENV['TERM'] != 'dumb'
define_method color do "\033[1;#{30+i}m#{self}\033[0m" end
define_method :"#{color}ish" do "\033[0;#{30+i}m#{self}\033[0m" end
define_method color do "#{ANSI_ESCAPE}[#{ANSI_BRIGHT};#{ANSI_COLOR_BASE+i}m#{self}#{ANSI_ESCAPE}[#{ANSI_NORMAL}m" end
define_method :"#{color}ish" do "#{ANSI_ESCAPE}[#{ANSI_NORMAL};#{ANSI_COLOR_BASE+i}m#{self}#{ANSI_ESCAPE}[#{ANSI_NORMAL}m" end
else
define_method color do self end
alias_method :"#{color}ish", color

View file

@ -164,11 +164,11 @@ EOS
it "colored multiline (default)" do
@hash.ai.should == <<-EOS.strip
{
1\e[1;30m => \e[0m{
:sym\e[1;30m => \e[0m{
\"str\"\e[1;30m => \e[0m{
[ 1, 2, 3 ]\e[1;30m => \e[0m{
{ :k => :v }\e[1;30m => \e[0m\e[1;33mHash < Object\e[0m
1\e[0;37m => \e[0m{
:sym\e[0;37m => \e[0m{
\"str\"\e[0;37m => \e[0m{
[ 1, 2, 3 ]\e[0;37m => \e[0m{
{ :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
}
}
}
@ -180,11 +180,11 @@ EOS
it "colored multiline indented" do
@hash.ai(:indent => 2).should == <<-EOS.strip
{
1\e[1;30m => \e[0m{
:sym\e[1;30m => \e[0m{
\"str\"\e[1;30m => \e[0m{
[ 1, 2, 3 ]\e[1;30m => \e[0m{
{ :k => :v }\e[1;30m => \e[0m\e[1;33mHash < Object\e[0m
1\e[0;37m => \e[0m{
:sym\e[0;37m => \e[0m{
\"str\"\e[0;37m => \e[0m{
[ 1, 2, 3 ]\e[0;37m => \e[0m{
{ :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
}
}
}
@ -194,7 +194,7 @@ EOS
end
it "colored single line" do
@hash.ai(:multiline => false).should == "{ 1\e[1;30m => \e[0m{ :sym\e[1;30m => \e[0m{ \"str\"\e[1;30m => \e[0m{ [ 1, 2, 3 ]\e[1;30m => \e[0m{ { :k => :v }\e[1;30m => \e[0m\e[1;33mHash < Object\e[0m } } } } }"
@hash.ai(:multiline => false).should == "{ 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } }"
end
end

View file

@ -14,5 +14,7 @@ describe "String extensions" do
it "should have black and pale colors" do
"black".send(:black).should == "black".send(:grayish)
"pale".send(:pale).should == "pale".send(:whiteish)
"pale".send(:pale).should == "\e[0;37mpale\e[0m"
"whiteish".send(:whiteish).should == "\e[0;37mwhiteish\e[0m"
end
end