mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Add Pry::Helpers::Text#with_line_numbers.
This commit is contained in:
parent
c49f9e3aba
commit
2744f866f7
3 changed files with 14 additions and 10 deletions
|
@ -53,8 +53,8 @@ class Pry
|
|||
end
|
||||
|
||||
opt.on_empty do
|
||||
text = add_line_numbers history.join("\n"), 0
|
||||
stagger_output text
|
||||
list = text.with_line_numbers history.join("\n"), 0
|
||||
stagger_output list
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,14 +23,6 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def add_line_numbers(lines, start_line)
|
||||
line_array = lines.each_line.to_a
|
||||
line_array.each_with_index.map do |line, idx|
|
||||
adjusted_index = idx + start_line
|
||||
"#{text.blue adjusted_index}: #{line}"
|
||||
end.join
|
||||
end
|
||||
|
||||
# if start_line is not false then add line numbers starting with start_line
|
||||
def render_output(should_flood, start_line, doc)
|
||||
if start_line
|
||||
|
|
|
@ -62,6 +62,18 @@ class Pry
|
|||
Pry.color = boolean
|
||||
end
|
||||
|
||||
# Returns _text_ in a numbered list, beginning at _offset_.
|
||||
#
|
||||
# @param [String, #each_line] text
|
||||
# @param [Fixnum] offset
|
||||
# @return [String]
|
||||
def with_line_numbers text, offset
|
||||
lines = text.each_line.to_a
|
||||
lines.each_with_index.map do |line, index|
|
||||
adjusted_index = index + offset
|
||||
"#{self.blue adjusted_index}: #{line}"
|
||||
end.join
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue