Add exporters, utils, and tests
This commit is contained in:
26
.termflow/exporters/graphviz_exporter.py
Normal file
26
.termflow/exporters/graphviz_exporter.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user