diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index 3c00aa8c..1ca45693 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -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 diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index d70a09e8..be84ad62 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -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 diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb index e00ff832..34fba788 100644 --- a/lib/pry/helpers/text.rb +++ b/lib/pry/helpers/text.rb @@ -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