class Athena::Console::Helper::Table::Style

Overview

Represents the overall style for a table. Including the characters that make up the row/column separators, crosses, cell formats, and default alignment.

This class provides a fluent interface for configuring each part of the style.

Defined in:

helper/table_style.cr

Instance Method Summary

Instance Method Detail

def align(align : ACON::Helper::Table::Alignment) : self #

Sets the default cell alignment for the table.

See ACON::Helper::Table::Alignment.


[View source]
def border_format(format : String) : self #

Sets the sprintf format string for the border, defaulting to "%s".

For example, if set to "~%s~" with the cell's content being text:

~+------+~
~|~ text ~|~
~+------+~

WARNING Customizing this format can mess with the formatting of the whole table.


[View source]
def cell_header_format(format : String) : self #

Sets the sprintf format string used for table headings, defaulting to "<info>%s</info>".


[View source]
def cell_row_content_format(format : String) : self #

Sets the sprintf format string used for cell contents, defaulting to " %s ".

For example, if set to " =%s= " with the cell's content being text:

+--------+
| =text= |
+--------+

[View source]
def cell_row_format(format : String) : self #

Sets the sprintf format string used for cell contents, defaulting to "%s".

For example, if set to "~%s~" with the cell's content being text:

+------+
|~ text ~|
+------+

WARNING Customizing this format can mess with the formatting of the whole table.


[View source]
def clone #

Returns a copy of self with all instance variables cloned.


[View source]
def crossing_chars(cross : String | Char, top_left : String | Char, top_middle : String | Char, top_right : String | Char, middle_right : String | Char, bottom_right : String | Char, bottom_middle : String | Char, bottom_left : String | Char, middle_left : String | Char, top_left_bottom : String | Char | Nil = nil, top_middle_bottom : String | Char | Nil = nil, top_right_bottom : String | Char | Nil = nil) : self #

Sets the crossing characters individually, defaulting to "+". See #default_crossing_char(char) to default them all to a single character.

1═══════════════2══════════════════════════2══════════════════3
║ ISBN          │ Title                    │ Author           ║
8═══════════════0══════════════════════════0══════════════════4
║ 99921-58-10-7 │ Divine Comedy            │ Dante Alighieri  ║
║ 9971-5-0210-0 │ A Tale of Two Cities     │ Charles Dickens  ║
8───────────────0──────────────────────────0──────────────────4
║ 960-425-059-0 │ The Lord of the Rings    │ J. R. R. Tolkien ║
║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie  ║
7═══════════════6══════════════════════════6══════════════════5

Legend:

  • #0 cross

  • #1 top_left

  • #2 top_middle

  • #3 top_right

  • #4 middle_right

  • #5 bottom_right

  • #6 bottom_middle

  • #7 bottom_left

  • #8 middle_left

  • #8 top_left_bottom - defaults to middle_left if nil

  • #0 top_middle_bottom - defaults to cross if nil

  • #4 top_right_bottom - defaults to middle_right if nil


[View source]
def default_crossing_char(char : String | Char) : self #

Sets the default character used for each cross type.

See #crossing_chars.


[View source]
def footer_title_format(format : String) : self #

Sets the sprintf format string used for [footer titles][Athena::Console::Helper::Table--headerfooter-titles], defaulting to "<fg=black;bg=white;options=bold> %s </>".


[View source]
def header_title_format(format : String) : self #

Sets the sprintf format string used for [header titles][Athena::Console::Helper::Table--headerfooter-titles], defaulting to "<fg=black;bg=white;options=bold> %s </>".


[View source]
def horizontal_border_chars(outside : String | Char, inside : String | Char | Nil = nil) : self #

Sets the horizontal border chars, defaulting to "-".

inside defaults to outside if not provided.

For example:

╔═══════════════╤══════════════════════════╤══════════════════╗
1 ISBN          2 Title                    │ Author           ║
╠═══════════════╪══════════════════════════╪══════════════════╣
║ 99921-58-10-7 │ Divine Comedy            │ Dante Alighieri  ║
║ 9971-5-0210-0 │ A Tale of Two Cities     │ Charles Dickens  ║
║ 960-425-059-0 │ The Lord of the Rings    │ J. R. R. Tolkien ║
║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie  ║
╚═══════════════╧══════════════════════════╧══════════════════╝

Legend:

  • #1 outside
  • #2 inside

[View source]
def padding_char(char : Char) : self #

Sets the the character that is added to the cell to ensure its content has the correct ACON::Helper::Table::Alignment, defaulting to ' '.

For example, if the padding character was '_' with a left alignment:

+-----+
| 7 __|
+-----+

[View source]
def vertical_border_chars(outside : String | Char, inside : String | Char | Nil = nil) : self #

Sets the vertical border chars, defaulting to "|".

inside defaults to outside if not provided.

For example:

╔═══════════════╤══════════════════════════╤══════════════════╗
║ ISBN          │ Title                    │ Author           ║
╠═══════1═══════╪══════════════════════════╪══════════════════╣
║ 99921-58-10-7 │ Divine Comedy            │ Dante Alighieri  ║
║ 9971-5-0210-0 │ A Tale of Two Cities     │ Charles Dickens  ║
╟───────2───────┼──────────────────────────┼──────────────────╢
║ 960-425-059-0 │ The Lord of the Rings    │ J. R. R. Tolkien ║
║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie  ║
╚═══════════════╧══════════════════════════╧══════════════════╝

Legend:

  • #1 outside
  • #2 inside

[View source]