graphs-tui
Terminal renderer for Mermaid and D2 diagrams in Rust.
Render flowcharts, state diagrams, pie charts, and D2 diagrams as clean Unicode or ASCII text in your terminal. Zero dependencies.
Features
- Mermaid Support: Flowcharts, state diagrams, pie charts
- D2 Support: Shapes, connections, containers, edge labels
- Unicode & ASCII: Beautiful Unicode boxes by default, ASCII fallback
- Auto-Detection: Automatically detects Mermaid vs D2 format
- Zero Dependencies: Pure Rust, no external crates
Installation
[]
= "0.1"
Examples
Mermaid Flowchart
use ;
let input = r#"flowchart LR
A[Start] --> B[Process]
B --> C{Decision}
C -->|Yes| D[Done]
C -->|No| B"#;
let output = render_mermaid_to_tui.unwrap;
println!;
Output:
┌─────┐ ┌───────┐ / \
│Start│───────▶│Process│───────▶<Dec>
└─────┘ └───────┘ \ /
│
┌────Yes─────┘
▼
┌────┐
│Done│
└────┘
Mermaid State Diagram
use ;
let input = r#"stateDiagram-v2
[*] --> Idle
Idle --> Running: start
Running --> Idle: stop
Running --> [*]: complete"#;
let output = render_state_diagram.unwrap;
println!;
Output:
(●)
│
▼
╭────╮
│Idle│◀──stop──┐
╰────╯ │
│ │
│start │
▼ │
╭───────╮ │
│Running│──────┘
╰───────╯
│
│complete
▼
(◉)
Mermaid Pie Chart
use ;
let input = r#"pie
title Project Status
"Completed" : 45
"In Progress" : 30
"Pending" : 15
"Blocked" : 10"#;
let output = render_pie_chart.unwrap;
println!;
Output:
Project Status
──────────────
Completed │██████████████ │ 45 (45.0%)
In Progress │█████████ │ 30 (30.0%)
Pending │▒▒▒▒▒ │ 15 (15.0%)
Blocked │▒▒▒ │ 10 (10.0%)
Total: 100
D2 Diagram
use ;
let input = r#"
user: User
server: Web Server
db: Database
user -> server: HTTP request
server -> db: SQL query
db -> server: Result
server -> user: Response
"#;
let output = render_d2_to_tui.unwrap;
println!;
Output:
┌────┐
│User│
└────┘
│
│HTTP request
▼
┌──────────┐
│Web Server│
└──────────┘
│
│SQL query
▼
┌────────┐
│Database│
└────────┘
D2 with Containers
use ;
let input = r#"
backend {
api: API Server
db: Database
cache: Redis
}
frontend {
web: React App
mobile: iOS App
}
web -> api
mobile -> api
api -> db
api -> cache
"#;
let output = render_d2_to_tui.unwrap;
println!;
Auto-Detection
use ;
let mermaid_input = "flowchart LR\n A --> B --> C";
let d2_input = "A -> B -> C";
// Auto-detect and render
let output1 = render_diagram.unwrap;
let output2 = render_diagram.unwrap;
// Check format
assert_eq!;
assert_eq!;
ASCII Mode
For environments without Unicode support:
use ;
let input = "flowchart LR\n A[Start] --> B[End]";
let options = RenderOptions ;
let output = render_mermaid_to_tui.unwrap;
println!;
Output:
+-----+ +---+
|Start|------->|End|
+-----+ +---+
Supported Syntax
Mermaid Flowcharts
| Feature | Syntax | Example |
|---|---|---|
| Directions | LR, RL, TB, BT |
flowchart LR |
| Rectangle | [label] |
A[My Node] |
| Rounded | (label) |
A(Rounded) |
| Circle | ((label)) |
A((Circle)) |
| Diamond | {label} |
A{Decision} |
| Cylinder | [(label)] |
DB[(Database)] |
| Stadium | ([label]) |
A([Stadium]) |
| Hexagon | {{label}} |
A{{Hexagon}} |
| Arrow | --> |
A --> B |
| Line | --- |
A --- B |
| Dotted | -.-> |
A -.-> B |
| Thick | ==> |
A ==> B |
| Label | -->|text| |
A -->|yes| B |
Mermaid State Diagrams
| Feature | Syntax | Example |
|---|---|---|
| State | StateName |
Idle |
| Start | [*] |
[*] --> Idle |
| End | [*] |
Done --> [*] |
| Transition | --> |
Idle --> Running |
| Label | : text |
Idle --> Running: start |
| Description | state "desc" as ID |
state "Waiting" as Wait |
D2 Diagrams
| Feature | Syntax | Example |
|---|---|---|
| Shape | id or id: label |
server: Web Server |
| Arrow | -> |
A -> B |
| Reverse | <- |
A <- B |
| Bidirectional | <-> |
A <-> B |
| Line | -- |
A -- B |
| Edge label | : text |
A -> B: request |
| Shape type | .shape: type |
db.shape: cylinder |
| Container | { } |
backend { api } |
Development
License
AGPL-3.0-or-later
Inspiration
Inspired by tariqshams/mermaidtui