Initial upload: TermDiagram v0.1.0
This commit is contained in:
49
src/termdiagram/generators/ascii_generator.py
Normal file
49
src/termdiagram/generators/ascii_generator.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from typing import List
|
||||
from ..models import Module
|
||||
|
||||
|
||||
class AsciiDiagramGenerator:
|
||||
def __init__(self):
|
||||
self.box_width = 40
|
||||
|
||||
def generate(self, modules: List[Module]) -> str:
|
||||
lines = []
|
||||
lines.append("Architecture Overview")
|
||||
lines.append("=" * 60)
|
||||
lines.append("")
|
||||
|
||||
for module in modules:
|
||||
self._render_module(lines, module, 0)
|
||||
lines.append("")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
def _render_module(self, lines: List[str], module: Module, indent: int):
|
||||
prefix = " " * indent
|
||||
lines.append(f"{prefix}[ Module ] {module.name}")
|
||||
|
||||
for cls in module.classes:
|
||||
self._render_class(lines, cls, indent + 1)
|
||||
|
||||
for func in module.functions:
|
||||
self._render_function(lines, func, indent + 1)
|
||||
|
||||
def _render_class(self, lines: List[str], cls, indent: int):
|
||||
prefix = " " * indent
|
||||
lines.append(f"{prefix}+---[ Class ] {cls.name}")
|
||||
|
||||
if cls.bases:
|
||||
lines.append(f"{prefix} inherits: {', '.join(cls.bases)}")
|
||||
|
||||
for method in cls.methods:
|
||||
self._render_method(lines, method, indent + 1)
|
||||
|
||||
def _render_method(self, lines: List[str], method, indent: int):
|
||||
prefix = " " * indent
|
||||
sig = f"({', '.join(method.params)})")
|
||||
lines.append(f"{prefix} |-- {method.name}{sig}")
|
||||
|
||||
def _render_function(self, lines: List[str], func, indent: int):
|
||||
prefix = " " * indent
|
||||
sig = f"({', '.join(func.params)})")
|
||||
lines.append(f"{prefix}-- {func.name}{sig}")
|
||||
Reference in New Issue
Block a user