render

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package render provides diagram renderers for PIDL protocols.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderString

func RenderString(format Format, p *pidl.Protocol) (string, error)

RenderString renders a protocol using the specified format.

Types

type D2Renderer added in v0.2.0

type D2Renderer struct {
	// SequenceRenderOptions contains common sequence diagram options.
	SequenceRenderOptions

	// Style determines the diagram style (sequence, flow, or arch).
	Style D2Style

	// ShowDescriptions includes flow descriptions as tooltips.
	ShowDescriptions bool

	// Direction sets the diagram direction (down, right, left, up).
	Direction string
}

D2Renderer renders PIDL protocols as D2 diagrams.

func NewD2 added in v0.2.0

func NewD2() *D2Renderer

NewD2 creates a new D2 renderer with default options (sequence diagram).

func NewD2Arch added in v0.2.0

func NewD2Arch() *D2Renderer

NewD2Arch creates a new D2 renderer for architecture diagrams.

func NewD2Flow added in v0.2.0

func NewD2Flow() *D2Renderer

NewD2Flow creates a new D2 renderer for data flow diagrams.

func (*D2Renderer) Format added in v0.2.0

func (r *D2Renderer) Format() Format

Format returns the output format.

func (*D2Renderer) Render added in v0.2.0

func (r *D2Renderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the D2 diagram to the writer.

func (*D2Renderer) RenderString added in v0.2.0

func (r *D2Renderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the D2 diagram as a string.

type D2Style added in v0.2.0

type D2Style string

D2Style represents different D2 diagram styles.

const (
	// D2StyleSequence renders as a sequence diagram.
	D2StyleSequence D2Style = "sequence"
	// D2StyleFlow renders as a data flow diagram.
	D2StyleFlow D2Style = "flow"
	// D2StyleArch renders as an architecture diagram with grouped entities.
	D2StyleArch D2Style = "arch"
)

type DOTRenderer

type DOTRenderer struct {
	// Title includes the protocol name as graph label.
	Title bool

	// RankDir sets the graph direction (LR, TB, RL, BT).
	RankDir string

	// MergeEdges combines multiple flows between the same entities.
	MergeEdges bool

	// ShowPhases groups nodes by phase using subgraphs.
	ShowPhases bool

	// ShowConditions includes condition text in edge labels.
	ShowConditions bool

	// ShowAnnotations includes annotation counts in edge labels.
	ShowAnnotations bool
}

DOTRenderer renders PIDL protocols as Graphviz DOT data flow diagrams.

func NewDOT

func NewDOT() *DOTRenderer

NewDOT creates a new DOT renderer with default options.

func (*DOTRenderer) Format

func (r *DOTRenderer) Format() Format

Format returns the output format.

func (*DOTRenderer) Render

func (r *DOTRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the DOT diagram to the writer.

func (*DOTRenderer) RenderString

func (r *DOTRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the DOT diagram as a string.

type Format

type Format string

Format represents a diagram output format.

const (
	FormatPlantUML         Format = "plantuml"
	FormatMermaid          Format = "mermaid"
	FormatMermaidState     Format = "mermaid-state"
	FormatMermaidComponent Format = "mermaid-component"
	FormatMermaidTrust     Format = "mermaid-trust"
	FormatMarkdownMatrix   Format = "markdown-matrix"
	FormatDOT              Format = "dot"
	FormatD2               Format = "d2"
	FormatD2Flow           Format = "d2-flow"
	FormatD2Arch           Format = "d2-arch"
	FormatSVG              Format = "svg"
	FormatSVGAnimated      Format = "svg-animated"
	FormatSVGNetwork       Format = "svg-network"
	FormatSVGComponent     Format = "svg-component"
	FormatSVGTrust         Format = "svg-trust"
)

func MustParseFormat

func MustParseFormat(s string) Format

MustParseFormat parses a format string, panicking on error.

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses a format string, returning an error if invalid.

func SupportedFormats

func SupportedFormats() []Format

SupportedFormats returns all supported output formats.

func (Format) FileExtension

func (f Format) FileExtension() string

FileExtension returns the conventional file extension for this format.

func (Format) String

func (f Format) String() string

String returns the format as a string.

type MarkdownMatrixRenderer added in v0.4.0

type MarkdownMatrixRenderer struct {
	// Title includes a title header
	Title bool
	// ShowDescription includes entity descriptions
	ShowDescription bool
}

MarkdownMatrixRenderer generates a Markdown table showing protocol roles by entity.

func NewMarkdownMatrix added in v0.4.0

func NewMarkdownMatrix() *MarkdownMatrixRenderer

NewMarkdownMatrix creates a new MarkdownMatrixRenderer with default settings.

func (*MarkdownMatrixRenderer) Format added in v0.4.0

func (r *MarkdownMatrixRenderer) Format() Format

Format returns the output format identifier.

func (*MarkdownMatrixRenderer) Render added in v0.4.0

Render writes the Markdown matrix to the given writer.

func (*MarkdownMatrixRenderer) RenderString added in v0.4.0

func (r *MarkdownMatrixRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the Markdown matrix as a string.

type MermaidComponentRenderer added in v0.4.0

type MermaidComponentRenderer struct {
	// Title includes the protocol name as diagram title.
	Title bool

	// ShowEntities includes entity nodes within components.
	ShowEntities bool

	// ShowRoles includes protocol roles on components.
	ShowRoles bool
}

MermaidComponentRenderer renders PIDL protocols as Mermaid flowcharts showing deployment components and their relationships.

func NewMermaidComponent added in v0.4.0

func NewMermaidComponent() *MermaidComponentRenderer

NewMermaidComponent creates a new Mermaid component diagram renderer.

func (*MermaidComponentRenderer) Format added in v0.4.0

func (r *MermaidComponentRenderer) Format() Format

Format returns the output format.

func (*MermaidComponentRenderer) Render added in v0.4.0

Render writes the Mermaid diagram to the writer.

func (*MermaidComponentRenderer) RenderString added in v0.4.0

func (r *MermaidComponentRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the Mermaid diagram as a string.

type MermaidRenderer

type MermaidRenderer struct {
	// SequenceRenderOptions contains common sequence diagram options.
	SequenceRenderOptions

	// Autonumber adds sequence numbers to messages.
	Autonumber bool
}

MermaidRenderer renders PIDL protocols as Mermaid sequence diagrams.

func NewMermaid

func NewMermaid() *MermaidRenderer

NewMermaid creates a new Mermaid renderer with default options.

func (*MermaidRenderer) Format

func (r *MermaidRenderer) Format() Format

Format returns the output format.

func (*MermaidRenderer) Render

func (r *MermaidRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the Mermaid diagram to the writer.

func (*MermaidRenderer) RenderString

func (r *MermaidRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the Mermaid diagram as a string.

type MermaidStateRenderer added in v0.4.0

type MermaidStateRenderer struct {
	// Title includes the protocol name as diagram title.
	Title bool

	// EntityFilter limits output to a specific entity (empty for all).
	EntityFilter string

	// ShowDescriptions includes state descriptions as notes.
	ShowDescriptions bool
}

MermaidStateRenderer renders PIDL protocols as Mermaid state diagrams.

func NewMermaidState added in v0.4.0

func NewMermaidState() *MermaidStateRenderer

NewMermaidState creates a new Mermaid state diagram renderer with default options.

func (*MermaidStateRenderer) Format added in v0.4.0

func (r *MermaidStateRenderer) Format() Format

Format returns the output format.

func (*MermaidStateRenderer) Render added in v0.4.0

func (r *MermaidStateRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the Mermaid state diagram to the writer.

func (*MermaidStateRenderer) RenderString added in v0.4.0

func (r *MermaidStateRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the Mermaid state diagram as a string.

type MermaidTrustRenderer added in v0.4.0

type MermaidTrustRenderer struct {
	// Title includes the protocol name as diagram title.
	Title bool

	// ShowCredentials includes credential types on edges.
	ShowCredentials bool

	// ShowComponents groups entities by their components.
	ShowComponents bool
}

MermaidTrustRenderer renders PIDL protocols as Mermaid flowcharts showing trust relationships between entities and components.

func NewMermaidTrust added in v0.4.0

func NewMermaidTrust() *MermaidTrustRenderer

NewMermaidTrust creates a new Mermaid trust diagram renderer.

func (*MermaidTrustRenderer) Format added in v0.4.0

func (r *MermaidTrustRenderer) Format() Format

Format returns the output format.

func (*MermaidTrustRenderer) Render added in v0.4.0

func (r *MermaidTrustRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the Mermaid diagram to the writer.

func (*MermaidTrustRenderer) RenderString added in v0.4.0

func (r *MermaidTrustRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the Mermaid diagram as a string.

type PlantUMLRenderer

type PlantUMLRenderer struct {
	// SequenceRenderOptions contains common sequence diagram options.
	SequenceRenderOptions

	// ShowDescriptions includes flow descriptions as notes.
	ShowDescriptions bool
}

PlantUMLRenderer renders PIDL protocols as PlantUML sequence diagrams.

func NewPlantUML

func NewPlantUML() *PlantUMLRenderer

NewPlantUML creates a new PlantUML renderer with default options.

func (*PlantUMLRenderer) Format

func (r *PlantUMLRenderer) Format() Format

Format returns the output format.

func (*PlantUMLRenderer) Render

func (r *PlantUMLRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the PlantUML diagram to the writer.

func (*PlantUMLRenderer) RenderString

func (r *PlantUMLRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the PlantUML diagram as a string.

type Renderer

type Renderer interface {
	// Render writes the diagram to the writer.
	Render(w io.Writer, p *pidl.Protocol) error

	// RenderString returns the diagram as a string.
	RenderString(p *pidl.Protocol) (string, error)

	// Format returns the output format name.
	Format() Format
}

Renderer generates diagram output from a Protocol.

func MustNew

func MustNew(format Format) Renderer

MustNew creates a Renderer for the specified format, panicking on error.

func New

func New(format Format) (Renderer, error)

New creates a Renderer for the specified format.

type SVGComponentRenderer added in v0.4.0

type SVGComponentRenderer struct {
	// Title includes a title header
	Title bool
	// Theme selects the color scheme ("light", "dark")
	Theme string
	// ShowEntities shows entities within components
	ShowEntities bool
	// ShowRoles shows protocol roles on components
	ShowRoles bool
}

SVGComponentRenderer renders deployment component diagrams as SVG.

func NewSVGComponent added in v0.4.0

func NewSVGComponent() *SVGComponentRenderer

NewSVGComponent creates a new SVGComponentRenderer with default settings.

func (*SVGComponentRenderer) Format added in v0.4.0

func (r *SVGComponentRenderer) Format() Format

Format returns the output format identifier.

func (*SVGComponentRenderer) Render added in v0.4.0

func (r *SVGComponentRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the SVG diagram to the given writer.

func (*SVGComponentRenderer) RenderString added in v0.4.0

func (r *SVGComponentRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the SVG diagram as a string.

type SVGNetworkRenderer added in v0.3.0

type SVGNetworkRenderer struct {
	// Animated enables CSS animations.
	Animated bool

	// Theme selects the color scheme ("light", "dark", "auto").
	Theme string

	// Title includes the protocol name in the diagram.
	Title bool

	// Direction is the layout direction ("horizontal" or "vertical").
	Direction string

	// ShowTrust enables trust level display on entities.
	ShowTrust bool

	// InferBoundariesFromTrust infers network boundaries from entity trust levels.
	InferBoundariesFromTrust bool

	// BoundaryOverrides allows CLI-specified boundary assignments.
	// Map of boundary ID to entity IDs.
	BoundaryOverrides map[string][]string
	// contains filtered or unexported fields
}

SVGNetworkRenderer renders PIDL protocols as SVG network boundary diagrams.

func NewSVGNetwork added in v0.3.0

func NewSVGNetwork() *SVGNetworkRenderer

NewSVGNetwork creates a new SVG network renderer with default options.

func (*SVGNetworkRenderer) AddBoundaryOverride added in v0.3.0

func (r *SVGNetworkRenderer) AddBoundaryOverride(boundaryID string, entityIDs []string)

AddBoundaryOverride adds a CLI-specified boundary assignment.

func (*SVGNetworkRenderer) Format added in v0.3.0

func (r *SVGNetworkRenderer) Format() Format

Format returns the output format.

func (*SVGNetworkRenderer) Render added in v0.3.0

func (r *SVGNetworkRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the SVG diagram to the writer.

func (*SVGNetworkRenderer) RenderString added in v0.3.0

func (r *SVGNetworkRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the SVG diagram as a string.

type SVGRenderer added in v0.3.0

type SVGRenderer struct {
	// SequenceRenderOptions contains common sequence diagram options.
	SequenceRenderOptions

	// Animated enables CSS animations (moving dots along message lines).
	// This is used by FormatSVGAnimated.
	Animated bool

	// Theme selects the color scheme ("light", "dark", "auto").
	Theme string

	// ShowStepNumbers shows step numbers on messages.
	ShowStepNumbers bool

	// ShowPhases renders phase boxes around grouped flows.
	ShowPhases bool

	// ParticipantSpacing sets horizontal spacing between participants.
	ParticipantSpacing int

	// MessageSpacing sets vertical spacing between messages.
	MessageSpacing int

	// Template is the name of a built-in template to use.
	Template string

	// TemplateDir is a path to a custom template directory.
	TemplateDir string

	// AnimationConfig contains global animation settings.
	AnimationConfig svg.AnimationConfig
	// contains filtered or unexported fields
}

SVGRenderer renders PIDL protocols as SVG sequence diagrams.

func NewSVG added in v0.3.0

func NewSVG() *SVGRenderer

NewSVG creates a new SVG renderer with default options.

func NewSVGAnimated added in v0.3.0

func NewSVGAnimated() *SVGRenderer

NewSVGAnimated creates a new SVG renderer with animations enabled.

func NewSVGWithTemplate added in v0.3.0

func NewSVGWithTemplate(templateName string) (*SVGRenderer, error)

NewSVGWithTemplate creates an SVG renderer using the specified template.

func NewSVGWithTemplateDir added in v0.3.0

func NewSVGWithTemplateDir(dir string) (*SVGRenderer, error)

NewSVGWithTemplateDir creates an SVG renderer using a template from a directory.

func (*SVGRenderer) Format added in v0.3.0

func (r *SVGRenderer) Format() Format

Format returns the output format.

func (*SVGRenderer) Render added in v0.3.0

func (r *SVGRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the SVG diagram to the writer.

func (*SVGRenderer) RenderString added in v0.3.0

func (r *SVGRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the SVG diagram as a string.

type SVGTrustRenderer added in v0.4.0

type SVGTrustRenderer struct {
	// Title includes a title header
	Title bool
	// Theme selects the color scheme ("light", "dark")
	Theme string
	// ShowCredentials shows credential types on edges
	ShowCredentials bool
	// ShowComponents uses component names instead of entity/component IDs
	ShowComponents bool
}

SVGTrustRenderer renders trust relationship diagrams as SVG.

func NewSVGTrust added in v0.4.0

func NewSVGTrust() *SVGTrustRenderer

NewSVGTrust creates a new SVGTrustRenderer with default settings.

func (*SVGTrustRenderer) Format added in v0.4.0

func (r *SVGTrustRenderer) Format() Format

Format returns the output format identifier.

func (*SVGTrustRenderer) Render added in v0.4.0

func (r *SVGTrustRenderer) Render(w io.Writer, p *pidl.Protocol) error

Render writes the SVG diagram to the given writer.

func (*SVGTrustRenderer) RenderString added in v0.4.0

func (r *SVGTrustRenderer) RenderString(p *pidl.Protocol) (string, error)

RenderString returns the SVG diagram as a string.

type SequenceRenderOptions added in v0.4.0

type SequenceRenderOptions struct {
	// Title includes the protocol name as diagram title.
	Title bool

	// ShowNotes renders flow notes.
	ShowNotes bool

	// ShowAnnotations renders flow annotations.
	ShowAnnotations bool

	// ShowConditions wraps conditional flows in opt blocks.
	ShowConditions bool

	// ShowAlternatives renders alternative paths.
	ShowAlternatives bool

	// ShowSecurity renders security requirement notes/badges.
	ShowSecurity bool
}

SequenceRenderOptions contains common options for sequence diagram renderers. Renderers can embed this struct to get standard options.

func DefaultSequenceRenderOptions added in v0.4.0

func DefaultSequenceRenderOptions() SequenceRenderOptions

DefaultSequenceRenderOptions returns the default sequence render options.

type TraceRenderer added in v0.4.0

type TraceRenderer struct {
	// ShowStates includes entity states in output.
	ShowStates bool
	// ShowTimings includes timing information.
	ShowTimings bool
	// HighlightSkipped emphasizes skipped flows.
	HighlightSkipped bool
}

TraceRenderer renders execution traces in various formats.

func NewTraceRenderer added in v0.4.0

func NewTraceRenderer() *TraceRenderer

NewTraceRenderer creates a new TraceRenderer with default options.

func (*TraceRenderer) Render added in v0.4.0

func (r *TraceRenderer) Render(w io.Writer, trace *pidl.ExecutionTrace, opts TraceTextOptions) error

Render implements the Renderer interface for trace format.

func (*TraceRenderer) RenderJSON added in v0.4.0

func (r *TraceRenderer) RenderJSON(trace *pidl.ExecutionTrace) ([]byte, error)

RenderJSON renders the trace as JSON (simply marshals the trace).

func (*TraceRenderer) RenderMermaid added in v0.4.0

func (r *TraceRenderer) RenderMermaid(trace *pidl.ExecutionTrace, p *pidl.Protocol) string

RenderMermaid renders the trace as a Mermaid sequence diagram.

func (*TraceRenderer) RenderSVG added in v0.4.0

func (r *TraceRenderer) RenderSVG(trace *pidl.ExecutionTrace, p *pidl.Protocol) (string, error)

RenderSVG renders the trace as an SVG sequence diagram.

func (*TraceRenderer) RenderText added in v0.4.0

func (r *TraceRenderer) RenderText(trace *pidl.ExecutionTrace, opts TraceTextOptions) string

RenderText renders the trace as formatted text.

type TraceRendererInterface added in v0.4.0

type TraceRendererInterface interface {
	RenderText(trace *pidl.ExecutionTrace, opts TraceTextOptions) string
	RenderMermaid(trace *pidl.ExecutionTrace, p *pidl.Protocol) string
	RenderSVG(trace *pidl.ExecutionTrace, p *pidl.Protocol) (string, error)
}

TraceRendererInterface defines the interface for trace renderers.

type TraceTextOptions added in v0.4.0

type TraceTextOptions struct {
	// ShowTimestamps includes step timestamps.
	ShowTimestamps bool
	// ShowStates shows entity states after each step.
	ShowStates bool
	// Compact uses single-line output per step.
	Compact bool
	// UseColors enables ANSI color codes (for terminals).
	UseColors bool
}

TraceTextOptions configures text trace rendering.

func DefaultTraceTextOptions added in v0.4.0

func DefaultTraceTextOptions() TraceTextOptions

DefaultTraceTextOptions returns default text rendering options.

Directories

Path Synopsis
Package svg provides SVG rendering utilities for PIDL protocols.
Package svg provides SVG rendering utilities for PIDL protocols.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL