mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Code: extract #max_lineno_width
from #to_s
"Code" means `Pry::Code`. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
92fe82dbd6
commit
7daf1d2ce9
1 changed files with 6 additions and 3 deletions
|
@ -293,14 +293,17 @@ class Pry
|
|||
Object.instance_method(:to_s).bind(self).call
|
||||
end
|
||||
|
||||
# @return [Integer] the number of digits in the last line.
|
||||
def max_lineno_width
|
||||
@lines.length > 0 ? @lines.last.lineno.to_s.length : 0
|
||||
end
|
||||
|
||||
# @return [String] a formatted representation (based on the configuration of
|
||||
# the object).
|
||||
def to_s
|
||||
max_width = @lines.last.lineno.to_s.length if @lines.length > 0
|
||||
|
||||
lines = @lines.map(&:dup).each do |loc|
|
||||
loc.colorize(@code_type) if Pry.color
|
||||
loc.add_line_number(max_width) if @with_line_numbers
|
||||
loc.add_line_number(max_lineno_width) if @with_line_numbers
|
||||
loc.add_marker(@marker_lineno) if @with_marker
|
||||
loc.indent(@indentation_num) if @with_indentation
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue