# ascii-table **Repository Path**: mirrors_acassen/ascii-table ## Basic Information - **Project Name**: ascii-table - **Description**: Tiny Ascii Table formatter library - **Primary Language**: Unknown - **License**: AGPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-12 - **Last Updated**: 2026-04-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Tiny ASCII Table library ======================== When you're working on the command-line interface (also called VTY), you're dealing with text formatted output. Most of the CLI available on network equipments are pretty straightforward, and honestly, most of the time, they're a bit boring. That's not a reason to hold back on proposing more fancy stuff. In this attempt to conquer something that some might call "useless", we're introducing a source code implementing a tiny, simple, and straightforward ASCII table API. There are a lot of libraries out there on this topic, but most of them depend on massive code bases and are over-engineered. Most of us just need something with around 300 lines of code. This C source code is simple enough to integrate into any existing codebase without any dependencies. # Content ``` * main.c : Demo program * Makefile : ... * table.c : Library source code file * table.h : Library header file ``` # Example ```C #include #include #include "table.h" int main(int argc, char **argv) { unsigned char buffer[4096] = {}; struct table *tbl; tbl = table_init(3, STYLE_SINGLE_LINE_ROUNDED); table_set_column(tbl, "#", "Column 1", "Bigfoot Column 2"); table_set_header_align(tbl, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER); table_set_column_align(tbl, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT); table_add_row(tbl, "1", "str1", "str11 very long long 3"); table_add_row(tbl, "2", "str2", "str21"); table_add_row(tbl, "3", "str3", "str31"); table_add_row_fmt(tbl, "%d|str%d|str%d1", 4, 4, 4); table_format(tbl, buffer, 4096); table_destroy(tbl); printf("%s\n", buffer); exit(0); } ``` # Give it a try $ make $ ./tiny-ascii-table -=[ Style & Aligmnent demo ]=- ╭───┬──────────┬────────────────────────╮ │ # │ Column 1 │ Bigfoot Column 2 │ ├───┼──────────┼────────────────────────┤ │ 1 │ str1 │ str11 very long long 3 │ │ 2 │ str2 │ str21 │ │ 3 │ str3 │ str31 │ │ 4 │ str4 │ str41 │ │ 5 │ str5 │ str51 │ │ 6 │ str6 │ str61 │ │ 7 │ str7 │ str71 │ ╰───┴──────────┴────────────────────────╯ -=[ Built-in Styles available ]=- -=[ Table Style : 0 ]=- +---+----------+------------------------+ | # | Column 1 | Bigfoot Column 2 | +---+----------+------------------------+ | 1 | str1 | str11 very long long 3 | | 2 | str2 | str21 | | 3 | str3 | str31 | | 4 | str4 | str41 | | 5 | str5 | str51 | | 6 | str6 | str61 | | 7 | str7 | str71 | +---+----------+------------------------+ -=[ Table Style : 1 ]=- ......................................... : # : Column 1 : Bigfoot Column 2 : ......................................... : 1 : str1 : str11 very long long 3 : : 2 : str2 : str21 : : 3 : str3 : str31 : : 4 : str4 : str41 : : 5 : str5 : str51 : : 6 : str6 : str61 : : 7 : str7 : str71 : ......................................... -=[ Table Style : 2 ]=- ┌───┬──────────┬────────────────────────┐ │ # │ Column 1 │ Bigfoot Column 2 │ ├───┼──────────┼────────────────────────┤ │ 1 │ str1 │ str11 very long long 3 │ │ 2 │ str2 │ str21 │ │ 3 │ str3 │ str31 │ │ 4 │ str4 │ str41 │ │ 5 │ str5 │ str51 │ │ 6 │ str6 │ str61 │ │ 7 │ str7 │ str71 │ └───┴──────────┴────────────────────────┘ -=[ Table Style : 3 ]=- ╭───┬──────────┬────────────────────────╮ │ # │ Column 1 │ Bigfoot Column 2 │ ├───┼──────────┼────────────────────────┤ │ 1 │ str1 │ str11 very long long 3 │ │ 2 │ str2 │ str21 │ │ 3 │ str3 │ str31 │ │ 4 │ str4 │ str41 │ │ 5 │ str5 │ str51 │ │ 6 │ str6 │ str61 │ │ 7 │ str7 │ str71 │ ╰───┴──────────┴────────────────────────╯ -=[ Table Style : 4 ]=- # │ Column 1 │ Bigfoot Column 2 ───┼──────────┼──────────────────────── 1 │ str1 │ str11 very long long 3 2 │ str2 │ str21 3 │ str3 │ str31 4 │ str4 │ str41 5 │ str5 │ str51 6 │ str6 │ str61 7 │ str7 │ str71 -=[ Table Style : 5 ]=- ╔═══╦══════════╦════════════════════════╗ ║ # ║ Column 1 ║ Bigfoot Column 2 ║ ╠═══╬══════════╬════════════════════════╣ ║ 1 ║ str1 ║ str11 very long long 3 ║ ║ 2 ║ str2 ║ str21 ║ ║ 3 ║ str3 ║ str31 ║ ║ 4 ║ str4 ║ str41 ║ ║ 5 ║ str5 ║ str51 ║ ║ 6 ║ str6 ║ str61 ║ ║ 7 ║ str7 ║ str71 ║ ╚═══╩══════════╩════════════════════════╝ -=[ Table Style : 6 ]=- ╔═══╤══════════╤════════════════════════╗ ║ # │ Column 1 │ Bigfoot Column 2 ║ ╟───┼──────────┼────────────────────────╢ ║ 1 │ str1 │ str11 very long long 3 ║ ║ 2 │ str2 │ str21 ║ ║ 3 │ str3 │ str31 ║ ║ 4 │ str4 │ str41 ║ ║ 5 │ str5 │ str51 ║ ║ 6 │ str6 │ str61 ║ ║ 7 │ str7 │ str71 ║ ╚═══╧══════════╧════════════════════════╝ -=[ Table Style : 7 ]=- # ║ Column 1 ║ Bigfoot Column 2 ═══╬══════════╬════════════════════════ 1 ║ str1 ║ str11 very long long 3 2 ║ str2 ║ str21 3 ║ str3 ║ str31 4 ║ str4 ║ str41 5 ║ str5 ║ str51 6 ║ str6 ║ str61 7 ║ str7 ║ str71 -=[ Table Style : 8 ]=- ┏━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ # ┃ Column 1 ┃ Bigfoot Column 2 ┃ ┣━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━┫ ┃ 1 ┃ str1 ┃ str11 very long long 3 ┃ ┃ 2 ┃ str2 ┃ str21 ┃ ┃ 3 ┃ str3 ┃ str31 ┃ ┃ 4 ┃ str4 ┃ str41 ┃ ┃ 5 ┃ str5 ┃ str51 ┃ ┃ 6 ┃ str6 ┃ str61 ┃ ┃ 7 ┃ str7 ┃ str71 ┃ ┗━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┛ -=[ Table Style : 9 ]=- # ┃ Column 1 ┃ Bigfoot Column 2 ━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━ 1 ┃ str1 ┃ str11 very long long 3 2 ┃ str2 ┃ str21 3 ┃ str3 ┃ str31 4 ┃ str4 ┃ str41 5 ┃ str5 ┃ str51 6 ┃ str6 ┃ str61 7 ┃ str7 ┃ str71 -=[ Table Style : 10 ]=- ┏━━━┯━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ # │ Column 1 │ Bigfoot Column 2 ┃ ┠───┼──────────┼────────────────────────┨ ┃ 1 │ str1 │ str11 very long long 3 ┃ ┃ 2 │ str2 │ str21 ┃ ┃ 3 │ str3 │ str31 ┃ ┃ 4 │ str4 │ str41 ┃ ┃ 5 │ str5 │ str51 ┃ ┃ 6 │ str6 │ str61 ┃ ┃ 7 │ str7 │ str71 ┃ ┗━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━┛ -=[ Table Style : 11 ]=- ┏━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ # ┃ Column 1 ┃ Bigfoot Column 2 ┃ ┣━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┫ ┃ 1 │ str1 │ str11 very long long 3 ┃ ┃ 2 │ str2 │ str21 ┃ ┃ 3 │ str3 │ str31 ┃ ┃ 4 │ str4 │ str41 ┃ ┃ 5 │ str5 │ str51 ┃ ┃ 6 │ str6 │ str61 ┃ ┃ 7 │ str7 │ str71 ┃ ┗━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━┛ -=[ Table Style : 12 ]=- ┏━━━┯━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ # │ Column 1 │ Bigfoot Column 2 ┃ ┣━━━┿━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━┫ ┃ 1 │ str1 │ str11 very long long 3 ┃ ┃ 2 │ str2 │ str21 ┃ ┃ 3 │ str3 │ str31 ┃ ┃ 4 │ str4 │ str41 ┃ ┃ 5 │ str5 │ str51 ┃ ┃ 6 │ str6 │ str61 ┃ ┃ 7 │ str7 │ str71 ┃ ┗━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━┛ -=[ Table Style : 13 ]=- ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜ ▌ # ┃ Column 1 ┃ Bigfoot Column 2 ▐ ▌━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━▐ ▌ 1 ┃ str1 ┃ str11 very long long 3 ▐ ▌ 2 ┃ str2 ┃ str21 ▐ ▌ 3 ┃ str3 ┃ str31 ▐ ▌ 4 ┃ str4 ┃ str41 ▐ ▌ 5 ┃ str5 ┃ str51 ▐ ▌ 6 ┃ str6 ┃ str61 ▐ ▌ 7 ┃ str7 ┃ str71 ▐ ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟ Nothing more, nothing less...