Sha256: dc564cb7d2fbe3eb6337592b3389973d5727ea62973af967f0308c1d6a4d4c8c
Contents?: true
Size: 773 Bytes
Versions: 85
Compression:
Stored size: 773 Bytes
Contents
require_relative "terminal" class Thor module Shell class ColumnPrinter attr_reader :stdout, :options def initialize(stdout, options = {}) @stdout = stdout @options = options @indent = options[:indent].to_i end def print(array) return if array.empty? colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2 array.each_with_index do |value, index| # Don't output trailing spaces when printing the last column if ((((index + 1) % (Terminal.terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length stdout.puts value else stdout.printf("%-#{colwidth}s", value) end end end end end end
Version data entries
85 entries across 85 versions & 9 rubygems