table (cellium v0.1.0)

View Source

The table widget module provides functionality for rendering tabular data with borders, headers, and rows. It supports various box styles and can render multi-column tables with configurable column widths.

Summary

Functions

Draws the bottom line of a table.

Draws the header line of a table.

Generates the bottom border line of a table.

Generates a row separator line for a table.

Generates the top border line of a table.

Handles keyboard events for editable tables.

Creates a new table widget with default dimensions (0x0).

Creates a new table widget with the specified identifier, width, and height.

Renders a complete table widget with headers and data.

Renders the table when it has focus (shows selected cell highlight).

Functions

draw_bottom(X, Y, Fg, Bg, Box, ColumnWidths, Buffer)

-spec draw_bottom(integer(),
                  integer(),
                  atom(),
                  atom(),
                  #box{top_left :: term(),
                       top :: term(),
                       top_divider :: term(),
                       top_right :: term(),
                       head_left :: term(),
                       head_vertical :: term(),
                       head_right :: term(),
                       head_row_left :: term(),
                       head_row_horizontal :: term(),
                       head_row_cross :: term(),
                       head_row_right :: term(),
                       mid_left :: term(),
                       mid_vertical :: term(),
                       mid_right :: term(),
                       row_left :: term(),
                       row_horizontal :: term(),
                       row_cross :: term(),
                       row_right :: term(),
                       foot_row_left :: term(),
                       foot_row_horizontal :: term(),
                       foot_row_cross :: term(),
                       foot_row_right :: term(),
                       foot_left :: term(),
                       foot_vertical :: term(),
                       foot_right :: term(),
                       bottom_left :: term(),
                       bottom :: term(),
                       bottom_divider :: term(),
                       bottom_right :: term(),
                       is_ascii :: term()},
                  [non_neg_integer()],
                  map()) ->
                     map().

Draws the bottom line of a table.

  • X: Starting X coordinate
  • Y: Starting Y coordinate
  • Fg: Foreground color
  • Bg: Background color
  • Box: Box style to use
  • ColumnWidths: List of column widths
  • Buffer: Current frame buffer
  • Returns: Updated buffer

draw_header(X, Y, Fg, Bg, Box, ColumnWidths, Buffer)

-spec draw_header(integer(),
                  integer(),
                  atom(),
                  atom(),
                  #box{top_left :: term(),
                       top :: term(),
                       top_divider :: term(),
                       top_right :: term(),
                       head_left :: term(),
                       head_vertical :: term(),
                       head_right :: term(),
                       head_row_left :: term(),
                       head_row_horizontal :: term(),
                       head_row_cross :: term(),
                       head_row_right :: term(),
                       mid_left :: term(),
                       mid_vertical :: term(),
                       mid_right :: term(),
                       row_left :: term(),
                       row_horizontal :: term(),
                       row_cross :: term(),
                       row_right :: term(),
                       foot_row_left :: term(),
                       foot_row_horizontal :: term(),
                       foot_row_cross :: term(),
                       foot_row_right :: term(),
                       foot_left :: term(),
                       foot_vertical :: term(),
                       foot_right :: term(),
                       bottom_left :: term(),
                       bottom :: term(),
                       bottom_divider :: term(),
                       bottom_right :: term(),
                       is_ascii :: term()},
                  [non_neg_integer()],
                  map()) ->
                     map().

Draws the header line of a table.

  • X: Starting X coordinate
  • Y: Starting Y coordinate
  • Fg: Foreground color
  • Bg: Background color
  • Box: Box style to use
  • ColumnWidths: List of column widths

draw_table(X, Y, Height, Fg, Bg, Box, ColumnWidths, Buffer)

-spec draw_table(integer(),
                 integer(),
                 integer(),
                 atom(),
                 atom(),
                 #box{top_left :: term(),
                      top :: term(),
                      top_divider :: term(),
                      top_right :: term(),
                      head_left :: term(),
                      head_vertical :: term(),
                      head_right :: term(),
                      head_row_left :: term(),
                      head_row_horizontal :: term(),
                      head_row_cross :: term(),
                      head_row_right :: term(),
                      mid_left :: term(),
                      mid_vertical :: term(),
                      mid_right :: term(),
                      row_left :: term(),
                      row_horizontal :: term(),
                      row_cross :: term(),
                      row_right :: term(),
                      foot_row_left :: term(),
                      foot_row_horizontal :: term(),
                      foot_row_cross :: term(),
                      foot_row_right :: term(),
                      foot_left :: term(),
                      foot_vertical :: term(),
                      foot_right :: term(),
                      bottom_left :: term(),
                      bottom :: term(),
                      bottom_divider :: term(),
                      bottom_right :: term(),
                      is_ascii :: term()},
                 [non_neg_integer()],
                 map()) ->
                    map().

Draws a complete table with borders.

Renders a table frame consisting of header, row separators, and bottom. Does not render content, only the structural elements.

  • X: Starting X coordinate
  • Y: Starting Y coordinate
  • Height: Number of rows to draw
  • Fg: Foreground color
  • Bg: Background color
  • Box: Box style record
  • ColumnWidths: List of column widths
  • Buffer: Current frame buffer
  • Returns: Updated buffer

get_bottom(Box, Widths)

-spec get_bottom(#box{top_left :: term(),
                      top :: term(),
                      top_divider :: term(),
                      top_right :: term(),
                      head_left :: term(),
                      head_vertical :: term(),
                      head_right :: term(),
                      head_row_left :: term(),
                      head_row_horizontal :: term(),
                      head_row_cross :: term(),
                      head_row_right :: term(),
                      mid_left :: term(),
                      mid_vertical :: term(),
                      mid_right :: term(),
                      row_left :: term(),
                      row_horizontal :: term(),
                      row_cross :: term(),
                      row_right :: term(),
                      foot_row_left :: term(),
                      foot_row_horizontal :: term(),
                      foot_row_cross :: term(),
                      foot_row_right :: term(),
                      foot_left :: term(),
                      foot_vertical :: term(),
                      foot_right :: term(),
                      bottom_left :: term(),
                      bottom :: term(),
                      bottom_divider :: term(),
                      bottom_right :: term(),
                      is_ascii :: term()},
                 [non_neg_integer()]) ->
                    string().

Generates the bottom border line of a table.

  • Box: The box style record defining border characters
  • Widths: List of column widths
  • Returns: A flattened iolist representing the bottom border

get_row(Box, Level, Widths)

-spec get_row(#box{top_left :: term(),
                   top :: term(),
                   top_divider :: term(),
                   top_right :: term(),
                   head_left :: term(),
                   head_vertical :: term(),
                   head_right :: term(),
                   head_row_left :: term(),
                   head_row_horizontal :: term(),
                   head_row_cross :: term(),
                   head_row_right :: term(),
                   mid_left :: term(),
                   mid_vertical :: term(),
                   mid_right :: term(),
                   row_left :: term(),
                   row_horizontal :: term(),
                   row_cross :: term(),
                   row_right :: term(),
                   foot_row_left :: term(),
                   foot_row_horizontal :: term(),
                   foot_row_cross :: term(),
                   foot_row_right :: term(),
                   foot_left :: term(),
                   foot_vertical :: term(),
                   foot_right :: term(),
                   bottom_left :: term(),
                   bottom :: term(),
                   bottom_divider :: term(),
                   bottom_right :: term(),
                   is_ascii :: term()},
              head | row | mid | foot,
              [non_neg_integer()]) ->
                 string().

Generates a row separator line for a table.

Different separator styles are available depending on the level:

  • head: Header row separator

  • row: Regular row separator

  • mid: Middle separator (minimal)

  • foot: Footer row separator

  • Box: The box style record defining border characters

  • Level: The type of row separator to generate

  • Widths: List of column widths

  • Returns: A flattened iolist representing the row separator

get_top(Box, Widths)

-spec get_top(#box{top_left :: term(),
                   top :: term(),
                   top_divider :: term(),
                   top_right :: term(),
                   head_left :: term(),
                   head_vertical :: term(),
                   head_right :: term(),
                   head_row_left :: term(),
                   head_row_horizontal :: term(),
                   head_row_cross :: term(),
                   head_row_right :: term(),
                   mid_left :: term(),
                   mid_vertical :: term(),
                   mid_right :: term(),
                   row_left :: term(),
                   row_horizontal :: term(),
                   row_cross :: term(),
                   row_right :: term(),
                   foot_row_left :: term(),
                   foot_row_horizontal :: term(),
                   foot_row_cross :: term(),
                   foot_row_right :: term(),
                   foot_left :: term(),
                   foot_vertical :: term(),
                   foot_right :: term(),
                   bottom_left :: term(),
                   bottom :: term(),
                   bottom_divider :: term(),
                   bottom_right :: term(),
                   is_ascii :: term()},
              [non_neg_integer()]) ->
                 string().

Generates the top border line of a table.

  • Box: The box style record defining border characters
  • Widths: List of column widths
  • Returns: A flattened iolist representing the top border

handle_event/2

-spec handle_event(term(), map()) -> map().

Handles keyboard events for editable tables.

new(Id)

-spec new(term()) -> map().

Creates a new table widget with default dimensions (0x0).

new(Id, Width, Height)

-spec new(term(), non_neg_integer(), non_neg_integer()) -> map().

Creates a new table widget with the specified identifier, width, and height.

Parameters:

  • Id: A unique identifier for the widget.
  • Width: Initial width of the table.
  • Height: Initial height of the table.

render(Widget, Buffer)

-spec render(map(), map()) -> map().

Renders a complete table widget with headers and data.

Draws a full table including frame, optional headers, and data rows.

  • Widget: Table widget map containing position, dimensions, headers, and rows
  • Buffer: Current frame buffer
  • Returns: Updated buffer

render_focused(Widget, Buffer)

-spec render_focused(map(), map()) -> map().

Renders the table when it has focus (shows selected cell highlight).