View Source Kalevala.Output.Tables (kalevala v0.1.0)

Process table tags into ANSI tables

Processes 3 tags, {table}, {row}, and {cell}.

Tables are automatically balanced and text in cells are centered.

Example table:

{table}
  {row}
    {cell}Player Name{/cell}
  {/row}
  {row}
    {cell}HP{/cell}
    {cell}{color foreground="red"}50/50{/color}{/cell}
  {/row}
{/table}

{table} Tag

This tag starts a new table. It can only contain {row} tags as children. Any whitespace is trimmed and ignored inside the table.

{row} Tag

This tag starts a new row. It can only contain {cell} tags as children. Any whitespace is trimmed and ignored inside the row.

{cell} Tag

This tag is a cell. It can contain strings and other tags that don't increase the width of the cell, e.g. color tags. Anything other than a string is not used to calculate the width of the cell, which is used for balacing the table.

Link to this section Summary

Functions

Build a list of padding spaces for a side of a cell

Display a cell's contents

Display a table

Find the max width of rows in a table

Get the total width of a row

Give table tags some "breathing" room

Validate cells in a row (are all cell tags)

Validate rows in a table (are all row tags and have valid cells)

Link to this section Functions

Link to this function

cell_padding(cell_padding)

View Source

Build a list of padding spaces for a side of a cell

Link to this function

display_cells(cells, cell_padding)

View Source

Display a cell's contents

Pads the left and right, "pulls" left when centering (if an odd number)

Link to this function

display_row(row, max_width, split_row)

View Source

Display a row's cells

Display a table

Find the max width of rows in a table

Get the total width of a row

Each cell tracks it's string width, plus 3 for built in padding

Link to this function

table_breathing_room(list)

View Source

Give table tags some "breathing" room

  • If there is text before the table and no newline, then make a new line
  • If there is text after the table and no newline, then make a new line

Validate cells in a row (are all cell tags)

Validate rows in a table (are all row tags and have valid cells)