flowchart

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package flowchart renders Mermaid flowcharts as top-down Unicode box diagrams for terminal display.

Investigation findings are authored in Mermaid (which renders natively on GitHub and in docs), but the terminal renderer (glamour) shows a ```mermaid block as raw source. This package converts a flowchart into boxes and arrows flowing top-to-bottom.

Top-down (rather than left-to-right) layout is used because real investigation diagrams have enough nodes that a horizontal layout overflows any terminal width: flowing downward, width grows only at forks (siblings sit side-by-side), never with chain length. The diagram must be printed OUTSIDE the markdown renderer — glamour word-wraps content and would corrupt the alignment.

The renderer builds a spanning forest from the flowchart's edges: most flows are a chain or a success/failure fork, which render as boxes joined by arrows. Edges that can't be tree edges — back-edges (retry loops), fan-in (two arrows into one node), cross-links — are rendered as "↪" references to the already-shown node, so cyclic and converging diagrams still render instead of falling back. Subgraphs are treated as transparent grouping. It falls back (ok=false) only when the input isn't a flowchart it can parse at all (non-flowchart diagram types, `&` multi-edge shorthand, or unrecognized syntax), so the caller can show the raw Mermaid source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(src string) (string, bool)

Render renders src as a top-down box diagram and returns ok=true, or returns ok=false when src isn't a parseable flowchart. On ok=false the caller should show the raw Mermaid source.

Types

type Segment

type Segment struct {
	Markdown string
	Diagram  string
}

Segment is a piece of findings content produced by SplitRenderable: either Markdown to be rendered by the caller's markdown renderer, or a Diagram — a pre-rendered ASCII diagram that must be printed verbatim (NOT through the markdown renderer, which would word-wrap and corrupt its alignment). Exactly one field is non-empty.

func SplitRenderable

func SplitRenderable(md string) []Segment

SplitRenderable splits findings markdown into segments, replacing each ```mermaid block that is a renderable flowchart with a Diagram segment. Blocks it cannot render are left inside the surrounding Markdown segment, so the raw Mermaid survives for the markdown renderer (and for GitHub/doc rendering).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL