Class: FatTable::TermFormatter
- Defined in:
- lib/fat_table/formatters/term_formatter.rb
Overview
Output the table as for a unicode-enabled ANSI terminal. This makes table gridlines drawable with unicode characters, as well as supporting colored text and backgrounds, and blink, and underline attributes. See TermFormatter.valid_colors for an Array of valid colors that you can use. The extent to which all of these are actually supported depends on your terminal. TermFormatter uses the +rainbow+ gem for forming colored strings. Use a
Constant Summary collapse
- UPPER_LEFT =
:stopdoc: Unicode line-drawing characters. We use double lines before and after the table and single lines for the sides and hlines between groups and footers.
"\u2552"- UPPER_RIGHT =
"\u2555"- DOUBLE_RULE =
"\u2550"- UPPER_TEE =
"\u2564"- VERTICAL_RULE =
"\u2502"- LEFT_TEE =
"\u251C"- HORIZONTAL_RULE =
"\u2500"- SINGLE_CROSS =
"\u253C"- RIGHT_TEE =
"\u2524"- LOWER_LEFT =
"\u2558"- LOWER_RIGHT =
"\u255B"- LOWER_TEE =
"\u2567"
Constants inherited from Formatter
Formatter::CLR_RE, Formatter::LOCATIONS
Instance Attribute Summary
Attributes inherited from Formatter
#footers, #format_at, #gfooters, #options, #table
Instance Method Summary collapse
-
#decorate_string(str, istruct) ⇒ Object
Add ANSI codes to string to implement the given decorations.
-
#initialize(table = Table.new, **options) ⇒ TermFormatter
constructor
Return a new TermFormatter for +table+.
Methods inherited from Formatter
#avg_footer, #avg_gfooter, default_format, #foot, #footer, #format, #format_cell, #format_for, #gfoot, #gfooter, #max_footer, #max_gfooter, #min_footer, #min_gfooter, #output, #sum_footer, #sum_gfooter
Constructor Details
#initialize(table = Table.new, **options) ⇒ TermFormatter
Return a new TermFormatter for +table+. You can set a few +options+ with the following hash-like parameters:
unicode:: if set true, use unicode characters to form the frame of the table on output; if set false, use ASCII characters for the frame. By default, this is true.
framecolor::
set to a string of the form '
27 28 29 30 31 32 33 34 35 |
# File 'lib/fat_table/formatters/term_formatter.rb', line 27 def initialize(table = Table.new, **) super [:unicode] = .fetch(:unicode, true) [:framecolor] = .fetch(:framecolor, 'none.none') return unless [:framecolor] =~ /(?<co>[-_a-zA-Z]*)(\.(?<bg>[-_a-zA-Z]*))/ [:frame_fg] = Regexp.last_match[:co].downcase unless Regexp.last_match[:co].blank? [:frame_bg] = Regexp.last_match[:bg].downcase unless Regexp.last_match[:bg].blank? end |
Instance Method Details
#decorate_string(str, istruct) ⇒ Object
Add ANSI codes to string to implement the given decorations
42 43 44 45 46 47 48 49 50 |
# File 'lib/fat_table/formatters/term_formatter.rb', line 42 def decorate_string(str, istruct) result = Rainbow(str) result = colorize(result, istruct[:color], istruct[:bgcolor]) result = result.bold if istruct[:bold] result = result.italic if istruct[:italic] result = result.underline if istruct[:underline] result = result.blink if istruct[:blink] result end |