From 5076aa576997a081379dc29c3b377265d83be415 Mon Sep 17 00:00:00 2001 From: Andrew Vos Date: Thu, 29 Nov 2012 12:03:34 +0000 Subject: [PATCH] take into account string that have ansi codes --- lib/pry/commands/ls.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb index 7266fb9f..34c568f8 100644 --- a/lib/pry/commands/ls.rb +++ b/lib/pry/commands/ls.rb @@ -288,17 +288,21 @@ class Pry # Add a new section to the output. Outputs nothing if the section would be empty. def output_section(heading, body) 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 def tablify things things = things.compact screen_width = TerminalInfo.screen_size[1] - maximum_width = things.map{|t| t.size}.max + 1 - columns = screen_width.div(maximum_width) + maximum_width = things.map{|t| Pry::Helpers::Text.strip_color(t).length}.max + Pry.config.ls.separator.length + columns = screen_width / maximum_width - "\n" + things.each_slice(columns).map do |slice| - slice.map {|s| s.ljust(maximum_width)}.join("") + things.each_slice(columns).map do |slice| + 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