diff --git a/.termflow/exporters/graphviz_exporter.py b/.termflow/exporters/graphviz_exporter.py new file mode 100644 index 0000000..6a6c0c4 --- /dev/null +++ b/.termflow/exporters/graphviz_exporter.py @@ -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)