A Nim library for generating plain-text tables (with Unicode and ANSI code support)
Procs
proc addColumn(t: Table; title: string = ""; width: int = 0; align: Alignment = Left) {....raises: [ValueError], tags: [], forbids: [].}
-
Add a column definition
- title: Column header (preβformat with embedded ANSI codes)
- if ALL column titles are empty = no header
- width: Fixed width (0 = autoβsize to content)
- align: Cell alignment (Left, Center, Right)
- title: Column header (preβformat with embedded ANSI codes)
proc renderTable(t: Table; separator = false; width: int = 0; outFile: File = stdout) {....raises: [IOError], tags: [ReadEnvEffect, WriteIOEffect], forbids: [].}
-
Render the table
- separator: If true, adds boxβdrawing borders between columns
- width: Maximum table width (0 = use terminal width for terminal, no limit for files)
- outFile: Output file (default stdout)
Example
import tabulator
var t = newTable()
t.addColumn("Product", width = 20)
t.addColumn("Price", align = Right)
t.addColumn("In Stock", align = Center)
t.addRow(@["Apple", "$2.50", "yes"])
t.addRow(@["Banana", "$1.20", "no"])
t.addRow(@["Cherry", "$15.00", "low"])
t.renderTable(separator = true)
Output:
ββββββββββββββββββββββββββ³ββββββββββ³ββββββββββββ
β Product β Price β In Stock β
β£βββββββββββββββββββββββββββββββββββββββββββββββ«
β Apple β $2.50 β yes β
β Banana β $1.20 β no β
β Cherry β $15.00 β low β
ββββββββββββββββββββββββββ»ββββββββββ»ββββββββββββ