class GLI::Commands::HelpModules::ListFormatter

Given a list of two-element lists, formats on the terminal

Public Instance Methods

output(output_device) click to toggle source

Output the list to the output_device

# File lib/gli/commands/help_modules/list_formatter.rb, line 12
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

Public Class Methods

new(list,wrapper_class=TextWrapper) click to toggle source
# File lib/gli/commands/help_modules/list_formatter.rb, line 6
def initialize(list,wrapper_class=TextWrapper)
  @list = list
  @wrapper_class = wrapper_class
end