Sha256: 4ba4e06dcc2789ca2fb341fba2b451e29e70ef374a677c53469fe16f25ea53fa

Contents?: true

Size: 782 Bytes

Versions: 57

Compression:

Stored size: 782 Bytes

Contents

require_relative "terminal"

class Bundler::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

57 entries across 57 versions & 3 rubygems

Version Path
rubygems-update-3.6.3 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.6.3 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.6.2 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.6.2 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.6.1 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.6.1 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.6.0 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.6.0 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.5.23 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.5.23 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.5.22 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.5.22 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.5.21 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.5.21 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.5.20 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.5.20 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.5.19 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
bundler-2.5.19 lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb
rubygems-update-3.5.18 bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb