Class: HelpFormatter
- Inherits:
-
RDoc::Markup::ToAnsi
- Object
- RDoc::Markup::ToAnsi
- HelpFormatter
- Defined in:
- lib/nswtopo/help_formatter.rb
Instance Method Summary collapse
- #accept_heading(heading) ⇒ Object
- #accept_list_item_start(list_item) ⇒ Object
- #accept_paragraph(paragraph) ⇒ Object
- #accept_verbatim(verbatim) ⇒ Object
- #init_tags ⇒ Object
-
#initialize(ansi) ⇒ HelpFormatter
constructor
A new instance of HelpFormatter.
- #start_accepting ⇒ Object
Constructor Details
#initialize(ansi) ⇒ HelpFormatter
Returns a new instance of HelpFormatter.
2 3 4 5 6 7 8 9 10 |
# 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 |
Instance Method Details
#accept_heading(heading) ⇒ Object
41 42 43 44 45 |
# 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) ⇒ Object
19 20 21 22 23 24 |
# 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) ⇒ Object
47 48 49 50 51 52 53 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
12 13 14 15 16 17 |
# File 'lib/nswtopo/help_formatter.rb', line 12 def 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 ⇒ Object
55 56 57 58 |
# File 'lib/nswtopo/help_formatter.rb', line 55 def start_accepting super @res = @ansi ? ["\e[0m"] : [] end |