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

Version Path
es_cli-0.1.0 vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/column_printer.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/thor-1.3.1/lib/thor/shell/column_printer.rb
thor-1.3.2 lib/thor/shell/column_printer.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/thor-1.3.1/lib/thor/shell/column_printer.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/thor-1.3.1/lib/thor/shell/column_printer.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/thor-1.3.1/lib/thor/shell/column_printer.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/thor-1.3.1/lib/thor/shell/column_printer.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/thor-1.3.1/lib/thor/shell/column_printer.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
thor-1.3.1 lib/thor/shell/column_printer.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb