tabulator

A Nim library for generating plain-text tables (with Unicode and ANSI code support)

Types

Alignment = enum
  Left, Center, Right
Table = ref object
Main object class

Consts

Version 
For checking the current version programmatically

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)
proc addRow(t: Table; cells: seq[string]) {....raises: [], tags: [], forbids: [].}
Add a row of data; cells are strings (pre‑format numbers, embed ANSI codes)
proc newTable(): Table {....raises: [], tags: [], forbids: [].}
Create a new empty table
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     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━━━┛