- Write documentation
- More assertions and checks (bad calls should not lead to segfaults)
- Remove MAX_COLS restriction (currently 11)
Library to print nicely formatted tables to stdout. Supports...
- Cells spanning over multiple columns or rows
- ANSI color sequences
- Newlines in cell content
- Alignment of numbers under decimal dot
Currently not supported...
- wchars
- Special chars like
\t
Include src/table.h
to use it. Invoke make
to run tests.
First, get a new table with get_empty_table()
.
Its current column and current row are set to 0.
Cell insertions into the table always occur at the current column and current row.
After a cell insertion, the current column advances.
When styling a cell, call a setting-changing function before the cell insertion.
Generated by running the tests:
Generated by running the tests of ccalc
:
The following functions are used to obtain a new table, print it, and free it after use.
Returns a new table without any lines or set cells. All cells are styled to be left-aligned.
Insertion begins at the upper left corner. You don't need to look into a Table
directly, it suffices to use the following functions to manipulate it.
Prints a table to stdout. This function is equivalent to fprint_table(table, stdout)
.
Prints a table to a specified stream.
Frees all dynamic memory allocated for this table. It may not be used any more.
The following functions change the position of next cell insertion.
Sets position of next cell insertion. x = 0
is leftmost column, y = 0
is first row.
Passing a large value for y
may malloc a lot of rows, so use with care!
Sets position of next cell insertion to the first column of next row relative to current insertion position.
These functions insert a cell at the current position and advances the position to the next column (in the same row).
When MAX_COLS
many cells have been inserted into a row, next_row
needs to be called.
An inserted cell can not be changed any more.
Adds an empty cell without any content.
Adds a cell with a specified text. You have to ensure that the passed pointer is still valid when the table is printed.
If you don't want to maintain the buffer yourself, use add_cell_fmt
.
The same as add_cell
, but frees the passed pointer on free_table
, so use with care!
Adds a cell with a text specified as if printed by printf
. Buffer allocation and cleanup will be taken care of.
Flavor of add_cell_fmt
that allows for va_lists, e.g. for a wrapper function.
Adds multiple cells with contents specified by a memory-contiguous 2D-Array. Insertion begins at current position, next position of insertion will be right to set cells in the same row. Strings will not be copied, so take care that pointers within the array are valid when the table is printed!
These functions style the cell that is added by next insertion (in the following called current cell). Already set cells can not be styled any more.
BorderStyle |
Description |
---|---|
BORDER_SINGLE |
A single line |
BORDER_DOUBLE |
A double line |
BORDER_NONE |
No line, useful for removing a line for a specific cell |
TextAlignment |
Description |
---|---|
ALIGN_LEFT |
left-aligned |
ALIGN_RIGHT |
right-aligned |
ALIGN_CENTER |
centered (rounded to the left) |
ALIGN_NUMBERS |
aligned under decimal dot and padding zeros |
Sets the default text alignment for each column.
Overrides text alignment for current cell.
Overrides text alignment for all cells of current row.
Inserts a horizontal line above the current row.
Inserts a vertical line left to current column,
Encloses the table in its current state by a box. Make sure to call next_row
after last row to include it in box.
Inserts vertical lines between all currently non-empty columns.
Sets the left border of the current cell independently of default value for current column.
Sets the above border for the current cell independently of default value for current row.
Sets span for current cell. span_x
denotes the number of columns to span over, span_y
denotes the number of rows to span over.