Sha256: dc564cb7d2fbe3eb6337592b3389973d5727ea62973af967f0308c1d6a4d4c8c

Contents?: true

Size: 773 Bytes

Versions: 87

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

87 entries across 86 versions & 10 rubygems

Version Path
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/column_printer.rb