class Thor::Shell::Basic

def print_table(array, options={})


colwidth:: Force the first column to colwidth spaces wide.
indent:: Indent the first column by indent value.
==== Options

Array[Array[String, String, ...]]
==== Parameters

Prints a table.
def print_table(array, options={})
  return if array.empty?
  formats, indent, colwidth = [], options[:indent].to_i, options[:colwidth]
  options[:truncate] = terminal_width if options[:truncate] == true
  formats << "%-#{colwidth + 2}s" if colwidth
  start = colwidth ? 1 : 0
  colcount = array.max{|a,b| a.size <=> b.size }.size
  maximas = []
  start.upto(colcount - 1) do |index|
    maxima = array.map {|row| row[index] ? row[index].to_s.size : 0 }.max
    maximas << maxima
    if index == colcount - 1
      # Don't output 2 trailing spaces when printing the last column
      formats << "%-s"
    else
      formats << "%-#{maxima + 2}s"
    end
  end
  formats[0] = formats[0].insert(0, " " * indent)
  formats << "%s"
  array.each do |row|
    sentence = ""
    row.each_with_index do |column, index|
      maxima = maximas[index]
      if column.is_a?(Numeric)
        if index == row.size - 1
          # Don't output 2 trailing spaces when printing the last column
          f = "%#{maxima}s"
        else
          f = "%#{maxima}s  "
        end
      else
        f = formats[index]
      end
      sentence << f % column.to_s
    end
    sentence = truncate(sentence, options[:truncate]) if options[:truncate]
    stdout.puts sentence
  end
end