Add #colorize.

This commit is contained in:
Rob Gleeson 2011-05-05 00:45:18 +01:00
parent 0a2c394d02
commit 551279d5c2
1 changed files with 6 additions and 7 deletions

View File

@ -23,16 +23,15 @@ class Pry
end end
end end
def colorize text
Pry.color ? CodeRay.scan(text.to_s, :ruby).term : text
end
def add_line_numbers(lines, start_line) def add_line_numbers(lines, start_line)
line_array = lines.each_line.to_a line_array = lines.each_line.to_a
line_array.each_with_index.map do |line, idx| line_array.each_with_index.map do |line, idx|
adjusted_index = idx + start_line adjusted_index = idx + start_line
if Pry.color "#{colorize adjusted_index}: #{line}"
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
"#{cindex}: #{line}"
else
"#{idx}: #{line}"
end
end.join end.join
end end