ubunatic.com

Terminal & TUI Stack

termaid Terminal Mermaid Diagrams, Rendered Cleanly.

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

Key facts

12-week commit activity

2026-10-26
View 12-week data table
Week startingCommits
2026-08-030
2026-08-100
2026-08-170
2026-08-240
2026-08-310
2026-09-070
2026-09-141
2026-09-210
2026-09-282
2026-10-056
2026-10-120
2026-10-190

Key Features

  • Renders Mermaid flowcharts and sequence diagrams with Unicode boxes and ANSI color themes.
  • Fits diagrams to terminal width by changing wide layouts or showing the source when they do not fit.
  • Finds Mermaid diagrams in Markdown, including code blocks without a `mermaid` label.
  • Includes an interactive Loom viewer and a separate renderer for documentation folders.

Verified Engineering 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)

Stack

Go 1.26.7, x/term, Loom TUI example, Unicode box drawing, ANSI themes

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.

Project details

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)
Source
This project is in an early phase; its repository is not public yet.

Layer composition

Terminal
Unicode box drawing, ANSI, CLI
Desktop
—
Inference / AI
—
Containers / VM
—
Web
—

termaid: the story behind the project

termaid takes Mermaid source—the text commonly used to describe flowcharts and sequence diagrams—and turns supported diagrams into Unicode drawings that fit in a terminal. It is a Go library and command line program for situations where a b…

Read the engineering story