Class: RDocF95::RI::AnsiFormatter
- Inherits:
-
AttributeFormatter
- Object
- Formatter
- AttributeFormatter
- RDocF95::RI::AnsiFormatter
- Defined in:
- lib/rdoc-f95/ri/formatter.rb
Overview
This formatter uses ANSI escape sequences to colorize stuff works with pagers such as man and less.
Constant Summary collapse
- HEADINGS =
{ 1 => ["\033[1;32m", "\033[m"], 2 => ["\033[4;32m", "\033[m"], 3 => ["\033[32m", "\033[m"], }
Constants inherited from AttributeFormatter
RDocF95::RI::AttributeFormatter::BOLD, RDocF95::RI::AttributeFormatter::CODE, RDocF95::RI::AttributeFormatter::ITALIC
Constants inherited from Formatter
Instance Attribute Summary
Attributes inherited from Formatter
Instance Method Summary collapse
- #bold_print(txt) ⇒ Object
- #display_heading(text, level, indent) ⇒ Object
-
#initialize(*args) ⇒ AnsiFormatter
constructor
A new instance of AnsiFormatter.
- #write_attribute_text(prefix, line) ⇒ Object
Methods inherited from AttributeFormatter
Methods inherited from Formatter
#blankline, #break_to_newline, #conv_html, #conv_markup, #display_flow, #display_flow_item, #display_list, #display_verbatim_flow_item, #draw_line, for, list, #raw_print_line, #strip_attributes, #wrap
Constructor Details
#initialize(*args) ⇒ AnsiFormatter
Returns a new instance of AnsiFormatter.
369 370 371 372 |
# File 'lib/rdoc-f95/ri/formatter.rb', line 369 def initialize(*args) super @output.print "\033[0m" end |
Instance Method Details
#bold_print(txt) ⇒ Object
389 390 391 |
# File 'lib/rdoc-f95/ri/formatter.rb', line 389 def bold_print(txt) @output.print "\033[1m#{txt}\033[m" end |
#display_heading(text, level, indent) ⇒ Object
399 400 401 402 403 404 405 406 |
# File 'lib/rdoc-f95/ri/formatter.rb', line 399 def display_heading(text, level, indent) level = 3 if level > 3 heading = HEADINGS[level] @output.print indent @output.print heading[0] @output.print strip_attributes(text) @output.puts heading[1] end |
#write_attribute_text(prefix, line) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/rdoc-f95/ri/formatter.rb', line 374 def write_attribute_text(prefix, line) @output.print prefix curr_attr = 0 line.each do |achar| attr = achar.attr if achar.attr != curr_attr update_attributes(achar.attr) curr_attr = achar.attr end @output.print achar.char end update_attributes(0) unless curr_attr.zero? @output.puts end |