Ubunatic Coding

Terminal & TUI Stack

termaid Terminal Mermaid Diagrams, Rendered Cleanly.

A width-aware Mermaid diagram engine for terminal emulators, interactive CLIs and coding sessions.

termaid — terminal preview

cat deploy.mmd | termaid --border rounded --theme plain
            ╭──────────╮
            │ End User │
            ╰───── HTTPS Request
                  │
                  │
            ╭─────▼─────╮
            │ Cloud CDN │
            ╰───── Forward
                  │
                  │
           ╭──────▼──────╮
           │ API Gateway │
           ╰──────│──────╯
                  │
                  ├──────────╮
        ╭─────────╯          │
        │                    │
╭───────▼───────╮    ╭───────▼──────╮
│ Redis Session │    │ Core Service │
╰───────────────╯    ╰───────│──────╯
                             │
       ╭─────────────────────┤
       │                   ╭─╯
╭──────▼─────╮    ┌────────▼───────┐
│ Primary DB │    ⬡  Kafka Events  ⬡
╰────────────╯    └────────────────┘

Static preview retained from the original page.

Why termaid?

Standard ASCII generators break in real terminal viewports. Here is how termaid solves it.

The Terminal Width Dilemma

When a standard ASCII diagram exceeds terminal columns (W), line wrapping tears rectangular borders apart into illegible noise.

termaid measures bounding boxes before drawing against an active 5% safety margin (W × 0.95). It dynamically re-routes wide LR graphs to vertical TD layouts and applies compact spacing. If a diagram still cannot fit cleanly, it gracefully falls back to displaying the raw Mermaid code block rather than printing corrupted ASCII.

LLM Output Sanitization

LLMs often include HTML tags (<br/>, <span>, <b>), non-standard line breaks, or inline comments. termaid automatically sanitizes and normalizes dirty input before parsing.

Feature Basic Renderers termaid
LLM HTML Output Crashes or misaligns Sanitizes & unescapes
Terminal Width Ignored (line wrap) 5% margin buffer
Auto-Rotation None Dynamic LR → TD
Overflow Guard Mangled ASCII Safe syntax fallback
Diagram Scope Flowcharts only Flowchart + Sequence

Engine Capabilities

Engineered for high resilience, speed, and clean terminal aesthetics.

🔀

Flowcharts & 9 Shapes

Supports rectangles, rounded boxes, stadiums, cylinders, circles, diamonds, hexagons, subroutines, and flag nodes with Sugiyama topological ranking.

⏱️

Sequence Diagrams

Renders lifelines, solid/dashed arrows, autonumbering, notes, and container blocks (alt, opt, loop, par).

📐

A* Orthogonal Router

Discrete grid pathfinder routes arrows around obstacles with automatic bitmask junction resolution (┼, ┬, ┴, ╭, ╰).

🛡️

Execution Bounds

Context deadlines bound rendering work so host tools can limit the time spent laying out a diagram.

📝

Markdown Extractor

Run termaid extract README.md to locate and transform all embedded Mermaid blocks into terminal diagrams in-place.

🎨

ANSI & TrueColor Themes

Adaptive, Dark, Light, High-Contrast, and Plain palettes with customizable border styles (Rounded, Sharp, Double, ASCII).

CLI Quickstart

Simple UNIX pipeable tool for everyday command-line workflows.

1. Pipe from Stdin

echo -e "flowchart TD\n  A[Start] --> B{Valid?}\n  B -->|Yes| C[Run]\n  B -->|No| D[Halt]" | termaid

2. Render File with Custom Theme

termaid -f architecture.mmd --theme dark --border rounded

3. Extract and Render Diagrams in Markdown Documents

termaid extract docs/Architecture.md

Embeddable Go Library API

The renderer can be used by Go command-line and terminal UI tools. Its packages use terminal-width support from golang.org/x/term; the repository also includes a separate Loom-based interactive example.

package main

import (
    "context"
    "fmt"
    "log"
    "time"

    "github.com/termaid/termaid"
)

func main() {
    diagram := `
    sequenceDiagram
      autonumber
      Client->>Gateway: POST /v1/checkout
      Gateway->>DB: INSERT order
      DB-->>Gateway: 201 Created
      Gateway-->>Client: 200 OK
    `

    opts := termaid.DefaultOptions()
    opts.Width = 100
    opts.Theme = termaid.ThemeAdaptive
    opts.BorderStyle = termaid.BorderStyleRounded
    opts.Timeout = 500 * time.Millisecond
    opts.FallbackOnOverflow = true

    ctx := context.Background()
    output, err := termaid.Render(ctx, diagram, opts)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(output)
}

// Or import modular subpackages directly:
// import "github.com/termaid/termaid/sanitize"
// import "github.com/termaid/termaid/canvas"

The module path shown here is the repository’s current internal module identifier. The source repository is private; this example describes the API rather than a public installation path.

Engineering story

Recent work made Mermaid rendering width-aware and added flowchart and sequence-diagram paths, Markdown extraction, themed Unicode output, and a Loom-free docs renderer.

Read the terminal Mermaid rendering story

Source availability and licensing

The source repository is private. Source files declare AGPL-3.0-or-later.

At a glance

Stack
Go 1.26.7, x/term, Loom TUI example, Unicode box drawing, ANSI themes
Milestones
Flowchart parser, layout engine and Unicode canvas (#003, #004, #005, 5bd4389) · Width-aware rendering, sequence diagrams and CLI (#006, #007, #008, 71ca813) · Interactive viewer and standalone docs renderer examples (#009, #010, 2dc76e7, d25d331)
Commits
48
Source
This project is in an early phase; its repository is not public yet.