class HelpFormatter

Public Class Methods

new(ansi) click to toggle source
Calls superclass method
# File lib/nswtopo/help_formatter.rb, line 2
def initialize(ansi)
  @ansi = ansi
  super()
  @headings.clear
  return unless @ansi
  @headings[1] = ["\e[1m", "\e[m"] # bold
  @headings[2] = ["\e[4m", "\e[m"] # underline
  @headings[3] = ["\e[3m", "\e[m"] # italic
end

Public Instance Methods

accept_heading(heading) click to toggle source
Calls superclass method
# File lib/nswtopo/help_formatter.rb, line 41
def accept_heading(heading)
  @indent += 2 unless heading.level == 1
  super
  @indent -= 2 unless heading.level == 1
end
accept_list_item_start(list_item) click to toggle source
Calls superclass method
# File lib/nswtopo/help_formatter.rb, line 19
def accept_list_item_start(list_item)
  @indent += 2
  super
  @res.pop if @res.last == ?\n
  @indent -= 2
end
accept_paragraph(paragraph) click to toggle source
# File lib/nswtopo/help_formatter.rb, line 47
def accept_paragraph(paragraph)
  @indent += 2
  text = paragraph.text.tr_s(?\r, ?\s).tr_s(?\n, ?\s)
  wrap attributes text
  @indent -= 2
  @res << ?\n
end
accept_verbatim(verbatim) click to toggle source
# File lib/nswtopo/help_formatter.rb, line 26
 def accept_verbatim(verbatim)
  indent = ?\s * (@indent + (@ansi ? 2 : 4))
  verbatim.parts.map(&:each_line).flat_map(&:entries).each.with_index do |line, index|
    case
    when !@ansi
      @res << indent << line
    when line.start_with?("$ ")
      @res << indent << "\e[90m$\e[;3m " << line[2..-1] << "\e[m"
    else
      @res << indent << "\e[90m> " << line << "\e[m"
    end
  end
  @res << ?\n
end
init_tags() click to toggle source
# File lib/nswtopo/help_formatter.rb, line 12
def init_tags
  return unless @ansi
  add_tag :BOLD, "\e[1m", "\e[m" # bold
  add_tag :EM,   "\e[3m", "\e[m" # italic
  add_tag :TT,   "\e[3m", "\e[m" # italic
end
start_accepting() click to toggle source
Calls superclass method
# File lib/nswtopo/help_formatter.rb, line 55
def start_accepting
  super
  @res = @ansi ? ["\e[0m"] : []
end