Sha256: d7ead1b601864049ca33bf83d7bc0f876703989bde71d98ae7140865e7d89e99

Contents?: true

Size: 669 Bytes

Versions: 8

Compression:

Stored size: 669 Bytes

Contents

module GLI
  module Commands
    module HelpModules
      # Given a list of two-element lists, formats on the terminal 
      class ListFormatter
        def initialize(list)
          @list = list
        end

        # Output the list to the output_device
        def output(output_device)
          return if @list.empty?
          max_width = @list.map { |_| _[0].length }.max
          wrapper = TextWrapper.new(Terminal.instance.size[0],4 + max_width + 3)
          @list.each do |(name,description)|
            output_device.printf("    %-#{max_width}s - %s\n",name,wrapper.wrap(String(description).strip))
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gli-2.1.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0.rc8 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0.rc7 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0.rc6 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0.rc5 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0.rc4 lib/gli/commands/help_modules/list_formatter.rb
gli-2.0.0.rc3 lib/gli/commands/help_modules/list_formatter.rb