copied from irb
# File debug-1.4.0/lib/debug/thread_client.rb, line 1100
def dump(name, strs)
strs = strs.sort
return if strs.empty?
line = "#{colorize_blue(name)}: "
# Attempt a single line
if fits_on_line?(strs, cols: strs.size, offset: "#{name}: ".length)
line += strs.join(MARGIN)
@output << line
return
end
# Multi-line
@output << line
# Dump with the largest # of columns that fits on a line
cols = strs.size
until fits_on_line?(strs, cols: cols, offset: MARGIN.length) || cols == 1
cols -= 1
end
widths = col_widths(strs, cols: cols)
strs.each_slice(cols) do |ss|
@output << ss.map.with_index { |s, i| "#{MARGIN}%-#{widths[i]}s" % s }.join
end
end