Class | RI::AnsiFormatter |
In: |
ri/ri_formatter.rb
|
Parent: | AttributeFormatter |
This formatter uses ANSI escape sequences to colorize stuff works with pages such as man and less.
HEADINGS | = | { 1 => [ "\033[1;32m", "\033[m" ] , 2 => ["\033[4;32m", "\033[m" ], 3 => ["\033[32m", "\033[m" ] |
ATTR_MAP | = | { BOLD => "1", ITALIC => "33", CODE => "36" |
# File ri/ri_formatter.rb, line 405 405: def initialize(*args) 406: print "\033[0m" 407: super 408: end
# File ri/ri_formatter.rb, line 426 426: def bold_print(txt) 427: print "\033[1m#{txt}\033[m" 428: end
# File ri/ri_formatter.rb, line 436 436: def display_heading(text, level, indent) 437: level = 3 if level > 3 438: heading = HEADINGS[level] 439: print indent 440: print heading[0] 441: print strip_attributes(text) 442: puts heading[1] 443: end
# File ri/ri_formatter.rb, line 410 410: def write_attribute_text(prefix, line) 411: print prefix 412: curr_attr = 0 413: line.each do |achar| 414: attr = achar.attr 415: if achar.attr != curr_attr 416: update_attributes(achar.attr) 417: curr_attr = achar.attr 418: end 419: print achar.char 420: end 421: update_attributes(0) unless curr_attr.zero? 422: puts 423: end