class Toys::Utils::HelpText::ListStringAssembler
@private
Attributes
result[R]
Public Class Methods
new(tool, subtools, recursive, search_term, separate_sources, indent, wrap_width, styled)
click to toggle source
# File lib/toys/utils/help_text.rb, line 643 def initialize(tool, subtools, recursive, search_term, separate_sources, indent, wrap_width, styled) require "toys/utils/terminal" @tool = tool @subtools = subtools @recursive = recursive @search_term = search_term @separate_sources = separate_sources @indent = indent @wrap_width = wrap_width assemble(styled) end
Private Instance Methods
add_header()
click to toggle source
# File lib/toys/utils/help_text.rb, line 667 def add_header top_line = @recursive ? "Recursive list of tools" : "List of tools" @lines << if @tool.root? "#{top_line}:" else "#{top_line} under #{bold(@tool.display_name)}:" end if @search_term @lines << "" @lines << "Showing search results for \"#{@search_term}\"" end end
add_list()
click to toggle source
# File lib/toys/utils/help_text.rb, line 681 def add_list @subtools.each do |source_name, subtool_list| @lines << "" if @separate_sources @lines << underline("From: #{source_name}") @lines << "" end subtool_list.each do |local_name, subtool| add_prefix_with_desc(bold(local_name), subtool.desc) end end end
add_prefix_with_desc(prefix, desc)
click to toggle source
# File lib/toys/utils/help_text.rb, line 694 def add_prefix_with_desc(prefix, desc) if desc.empty? @lines << prefix elsif !desc.is_a?(WrappableString) @lines << "#{prefix} - #{desc}" else desc = wrap_indent(WrappableString.new(["#{prefix} -"] + desc.fragments)) @lines << desc[0] desc[1..-1].each do |line| @lines << indent_str(line) end end end
assemble(styled)
click to toggle source
# File lib/toys/utils/help_text.rb, line 660 def assemble(styled) @lines = Utils::Terminal.new(output: ::StringIO.new, styled: styled) add_header add_list @result = @lines.output.string end
bold(str)
click to toggle source
# File lib/toys/utils/help_text.rb, line 713 def bold(str) @lines.apply_styles(str, :bold) end
indent_str(str)
click to toggle source
# File lib/toys/utils/help_text.rb, line 721 def indent_str(str) "#{' ' * @indent}#{str}" end
underline(str)
click to toggle source
# File lib/toys/utils/help_text.rb, line 717 def underline(str) @lines.apply_styles(str, :underline) end
wrap_indent(input)
click to toggle source
# File lib/toys/utils/help_text.rb, line 708 def wrap_indent(input) return WrappableString.wrap_lines(input, nil) unless @wrap_width WrappableString.wrap_lines(input, @wrap_width, @wrap_width - @indent) end