27 lines
675 B
Python
27 lines
675 B
Python
"""Graphviz export functionality."""
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
class GraphvizExporter:
|
|
"""Exports diagrams to Graphviz format."""
|
|
|
|
def generate_dot(
|
|
self,
|
|
commands: List[str],
|
|
title: str = "Command Flow",
|
|
) -> str:
|
|
"""Generate DOT graph."""
|
|
lines = ["digraph {\n", f' label="{title}"\n', ' node [shape=box]\n\n']
|
|
|
|
for i, cmd in enumerate(commands):
|
|
safe_cmd = cmd.replace('"', '\\"')
|
|
lines.append(f' n{i} [label="{safe_cmd}"]\n')
|
|
|
|
if i > 0:
|
|
lines.append(f' n{{i-1}} -> n{{i}}\n')
|
|
|
|
lines.append("}\n")
|
|
|
|
return "".join(lines)
|