1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Fixed a 1.8 regression for the 'colorize' command.

This commit is contained in:
epitron 2011-04-22 02:47:06 -04:00
parent 82d83f96e6
commit 411737a378
2 changed files with 30 additions and 11 deletions

View file

@ -47,20 +47,39 @@ class Pry
# 1 => bright
# 0 => normal
#
[ :black, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
define_method "bright_#{color}" do |str|
Pry.color ? "\033[1;#{30+i}m#{str}\033[0m" : str
end
COLORS = {
"black" => 0,
"red" => 1,
"green" => 2,
"yellow" => 3,
"blue" => 4,
"purple" => 5,
"magenta" => 5,
"cyan" => 6,
"white" => 7
}
COLORS.each do |color, i|
define_method color do |str|
Pry.color ? "\033[0;#{30+i}m#{str}\033[0m" : str
end
define_method "bright_#{color}" do |str|
Pry.color ? "\033[1;#{30+i}m#{str}\033[0m" : str
end
end
alias_method :magenta, :purple
alias_method :bright_magenta, :bright_purple
alias_method :grey, :bright_black
alias_method :gray, :bright_black
require 'set'
VALID_COLORS = Set.new(
COLORS.keys +
COLORS.keys.map{|k| "bright_#{k}" } +
["grey", "gray"]
)
def bold(text)
Pry.color ? "\e[1m#{text}\e[0m" : text
end
@ -84,12 +103,12 @@ class Pry
# token is an opening tag!
if /<([\w\d_]+)>/ =~ token and respond_to?($1) #valid_tag?($1)
if /<([\w\d_]+)>/ =~ token and VALID_COLORS.include?($1) #valid_tag?($1)
stack.push $1
# token is a closing tag!
elsif /<\/([\w\d_]+)>/ =~ token and respond_to?($1) # valid_tag?($1)
elsif /<\/([\w\d_]+)>/ =~ token and VALID_COLORS.include?($1) # valid_tag?($1)
# if this color is on the stack somwehere...
if pos = stack.rindex($1)

View file

@ -266,11 +266,11 @@ e.g: gist -d my_method
end
end # rescue
end # gems
end # gems.each
end
command "gems", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg|
command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg|
gems = Gem.source_index.gems.values.group_by(&:name)
if arg
query = Regexp.new(arg, Regexp::IGNORECASE)
@ -289,7 +289,7 @@ e.g: gist -d my_method
end
command "whereami", "Show the code context for the session. Shows AROUND lines around the invocation line. AROUND defaults to 5 lines. " do |num|
command "whereami", "Show the code context for the session. (whereami <n> shows <n> extra lines of code around the invocation line. Default: 5)" do |num|
file = target.eval('__FILE__')
line_num = target.eval('__LINE__')
klass = target.eval('self.class')