Sha256: 17f53a229a898360e7b25b1454c69fd58b35c31e8783a54a0378be24aab1ac82

Contents?: true

Size: 739 Bytes

Versions: 56

Compression:

Stored size: 739 Bytes

Contents

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

        # Output the list to the output_device
        def output(output_device)
          return if @list.empty?
          max_width = @list.map { |_| _[0].length }.max
          wrapper = @wrapper_class.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

56 entries across 56 versions & 2 rubygems

Version Path
gli-2.22.1 lib/gli/commands/help_modules/list_formatter.rb
gli-2.22.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.21.5 lib/gli/commands/help_modules/list_formatter.rb
gli-2.21.4 lib/gli/commands/help_modules/list_formatter.rb
gli-2.21.3 lib/gli/commands/help_modules/list_formatter.rb
gli-2.21.2 lib/gli/commands/help_modules/list_formatter.rb
gli-2.21.1 lib/gli/commands/help_modules/list_formatter.rb
gli-2.21.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.20.1 lib/gli/commands/help_modules/list_formatter.rb
gli-2.20.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.19.2 lib/gli/commands/help_modules/list_formatter.rb
gli-2.19.1 lib/gli/commands/help_modules/list_formatter.rb
gli-2.19.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.18.2 lib/gli/commands/help_modules/list_formatter.rb
gli-2.18.1 lib/gli/commands/help_modules/list_formatter.rb
gli-2.18.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.17.2 lib/gli/commands/help_modules/list_formatter.rb
gli-2.17.1 lib/gli/commands/help_modules/list_formatter.rb
gli-2.17.0 lib/gli/commands/help_modules/list_formatter.rb
gli-2.16.1 lib/gli/commands/help_modules/list_formatter.rb