mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Minor simplification
This commit is contained in:
parent
3849b4a7bd
commit
59b7099293
3 changed files with 6 additions and 8 deletions
|
@ -6,7 +6,7 @@
|
||||||
class String
|
class String
|
||||||
#
|
#
|
||||||
# ANSI color codes:
|
# ANSI color codes:
|
||||||
# \033 => escape
|
# \e => escape
|
||||||
# 30 => color base
|
# 30 => color base
|
||||||
# 1 => bright
|
# 1 => bright
|
||||||
# 0 => normal
|
# 0 => normal
|
||||||
|
@ -17,11 +17,11 @@ class String
|
||||||
%w(gray red green yellow blue purple cyan white).zip(
|
%w(gray red green yellow blue purple cyan white).zip(
|
||||||
%w(black darkred darkgreen brown navy darkmagenta darkcyan slategray)).each_with_index do |(color, shade), i|
|
%w(black darkred darkgreen brown navy darkmagenta darkcyan slategray)).each_with_index do |(color, shade), i|
|
||||||
define_method color do |*html|
|
define_method color do |*html|
|
||||||
html[0] ? %Q|<kbd style="color:#{color}">#{self}</kbd>| : "\033[1;#{30+i}m#{self}\033[0m"
|
html[0] ? %Q|<kbd style="color:#{color}">#{self}</kbd>| : "\e[1;#{30+i}m#{self}\e[0m"
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method "#{color}ish" do |*html|
|
define_method "#{color}ish" do |*html|
|
||||||
html[0] ? %Q|<kbd style="color:#{shade}">#{self}</kbd>| : "\033[0;#{30+i}m#{self}\033[0m"
|
html[0] ? %Q|<kbd style="color:#{shade}">#{self}</kbd>| : "\e[0;#{30+i}m#{self}\e[0m"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -154,9 +154,7 @@ module AwesomePrint
|
||||||
# Format a Struct. If @options[:indent] if negative left align hash keys.
|
# Format a Struct. If @options[:indent] if negative left align hash keys.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_struct(s)
|
def awesome_struct(s)
|
||||||
h = {}
|
awesome_hash(Hash[s.members.zip(s.values)])
|
||||||
s.each_pair { |k,v| h[k] = v }
|
|
||||||
awesome_hash(h)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Format Class object.
|
# Format Class object.
|
||||||
|
|
|
@ -3,11 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||||
describe "String extensions" do
|
describe "String extensions" do
|
||||||
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
|
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
|
||||||
it "should have #{color} color" do
|
it "should have #{color} color" do
|
||||||
color.to_s.send(color).should == "\033[1;#{30+i}m#{color}\033[0m"
|
color.to_s.send(color).should == "\e[1;#{30+i}m#{color}\e[0m"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have #{color}ish color" do
|
it "should have #{color}ish color" do
|
||||||
color.to_s.send(:"#{color}ish").should == "\033[0;#{30+i}m#{color}\033[0m"
|
color.to_s.send(:"#{color}ish").should == "\e[0;#{30+i}m#{color}\e[0m"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue