take into account string that have ansi codes

This commit is contained in:
Andrew Vos 2012-11-29 12:03:34 +00:00
parent cd5f0ae3be
commit 5076aa5769
1 changed files with 9 additions and 5 deletions

View File

@ -288,17 +288,21 @@ class Pry
# Add a new section to the output. Outputs nothing if the section would be empty. # Add a new section to the output. Outputs nothing if the section would be empty.
def output_section(heading, body) def output_section(heading, body)
return if body.compact.empty? return if body.compact.empty?
output.puts "#{text.bold(color(:heading, heading))}: #{tablify(body)}" output.puts "#{text.bold(color(:heading, heading))}: \n#{tablify(body)}"
end end
def tablify things def tablify things
things = things.compact things = things.compact
screen_width = TerminalInfo.screen_size[1] screen_width = TerminalInfo.screen_size[1]
maximum_width = things.map{|t| t.size}.max + 1 maximum_width = things.map{|t| Pry::Helpers::Text.strip_color(t).length}.max + Pry.config.ls.separator.length
columns = screen_width.div(maximum_width) columns = screen_width / maximum_width
"\n" + things.each_slice(columns).map do |slice| things.each_slice(columns).map do |slice|
slice.map {|s| s.ljust(maximum_width)}.join("") slice.map do |s|
padding_width = maximum_width - Pry::Helpers::Text.strip_color(s).length
padding = Pry.config.ls.separator.ljust(padding_width, Pry.config.ls.separator)
s + padding
end.join("")
end.join("\n") end.join("\n")
end end