Documentation
¶
Overview ¶
Package output provides a registry for dynamically registering renderer factories.
The registry is an opt-in plugin system. By default, formats are used directly via their constructors (NewMarkdownTable, NewD2Diagram, etc.). Use Register/Create when you need runtime-dispatchable format selection, e.g.:
output.Register(output.FormatJSON, func() output.Renderer { return myCustomJSONRenderer })
renderer, _ := output.Create(output.FormatJSON)
The registry is thread-safe.
Package output provides consistent output formatting for CLI applications.
Index ¶
- Constants
- Variables
- func AddTreeNodes(nodes *[]GraphNode, edges *[]GraphEdge, node *TreeNode, parentID string, ...)
- func AssertTreeNodeDepth(t *testing.T, root, child, grandchild *TreeNode)
- func DefaultGraphNodeLabel(header, cell string) string
- func FilledStrings(n int, value string) []string
- func IsRegistered(format Format) bool
- func MarshalJSON(v any) ([]byte, error)
- func MarshalJSONIndent(v any, prefix, indent string) ([]byte, error)
- func MarshalTSV(data any) ([]byte, error)
- func MarshalXML(v any) ([]byte, error)
- func MarshalXMLFromTableData(data *TableData) ([]byte, error)
- func MarshalXMLIndent(v any, prefix, indent string) (result []byte, err error)
- func MarshalYAML(v any) ([]byte, error)
- func MustRender(r Renderer) string
- func NewBrandedID[Brand any](value string) id.ID[Brand, string]
- func Register(format Format, factory RendererFactory) error
- func UnmarshalJSON(data []byte, v any) error
- func UnmarshalYAML(data []byte, v any) error
- func Unregister(format Format)
- type ASCIITreeRenderer
- type Alignment
- type BrandedID
- type CSVWriter
- type ColorMode
- type D2ArrowType
- type D2Column
- type D2Constraint
- type D2Diagram
- func (d *D2Diagram) AddClass(name string, style D2NodeStyle) *D2Diagram
- func (d *D2Diagram) AddEdge(edge D2Edge) *D2Diagram
- func (d *D2Diagram) AddEdgeSimple(from, to string) *D2Diagram
- func (d *D2Diagram) AddLabeledEdge(from, to, label string) *D2Diagram
- func (d *D2Diagram) AddNode(node D2Node) *D2Diagram
- func (d *D2Diagram) AddNodeSimple(id, label string) *D2Diagram
- func (d *D2Diagram) AddNodeWithShape(id, label string, shape D2NodeShape) *D2Diagram
- func (d *D2Diagram) AddTable(name string, columns []D2Column) *D2Diagram
- func (d *D2Diagram) Render() (string, error)
- func (d *D2Diagram) SetDirection(dir D2Direction) *D2Diagram
- func (d *D2Diagram) SetEdges(edges []GraphEdge)
- func (d *D2Diagram) SetLayout(engine string) *D2Diagram
- func (d *D2Diagram) SetNodes(nodes []GraphNode)
- func (d *D2Diagram) SetTitle(title string) *D2Diagram
- type D2Direction
- type D2Edge
- type D2EdgeStyle
- type D2Node
- type D2NodeID
- type D2NodeIDBrand
- type D2NodeLabel
- type D2NodeLabelBrand
- type D2NodeShape
- type D2NodeStyle
- type D2Table
- type DOTRenderer
- type DelimitedWriter
- type EdgeStyle
- type ExpectedOutput
- type Format
- type FormatCategory
- type GraphEdge
- type GraphNode
- type GraphNodeID
- type GraphNodeIDBrand
- type GraphNodeLabel
- type GraphNodeLabelBrand
- type GraphNodeLabelFunc
- type GraphRenderer
- type GraphRendererMixin
- type GraphShape
- type GraphStyle
- type HTMLRenderer
- type HTMLTreeRenderer
- type InvalidFormatError
- type JSONWriter
- type MarkdownTable
- type MermaidRenderer
- type OutputFormatdeprecated
- type Renderer
- type RendererFactory
- type RowEdge
- type SortBy
- type StreamingHTMLRenderer
- type StreamingRenderer
- type TSVWriter
- type TableData
- type TableRenderer
- type TreeNode
- type TreeNodeID
- type TreeNodeIDBrand
- type TreeNodeIDFunc
- type TreeNodeLabel
- type TreeNodeLabelBrand
- type TreeOutputRenderer
- type XMLWriter
Constants ¶
const ( OutputFormatTable = FormatTable OutputFormatJSON = FormatJSON OutputFormatCSV = FormatCSV OutputFormatTSV = FormatTSV OutputFormatXML = FormatXML OutputFormatMarkdown = FormatMarkdown OutputFormatD2 = FormatD2 OutputFormatYAML = FormatYAML OutputFormatHTML = FormatHTML OutputFormatTree = FormatTree OutputFormatMermaid = FormatMermaid OutputFormatDOT = FormatDOT )
Backward compatibility aliases for format constants.
Variables ¶
var AllFormats = []Format{ FormatTable, FormatJSON, FormatCSV, FormatTSV, FormatMarkdown, FormatXML, FormatD2, FormatYAML, FormatHTML, FormatTree, FormatMermaid, FormatDOT, }
AllFormats contains all valid output format values. Use this for testing AllowedValues or generating help text.
var ErrFormatAlreadyRegistered = errors.New("format already registered")
ErrFormatAlreadyRegistered is returned when a format is already registered.
var ErrInvalidColorMode = errors.New("invalid color mode")
ErrInvalidColorMode is returned when an invalid color mode is provided.
var ErrInvalidD2ArrowType = errors.New("invalid D2 arrow type")
ErrInvalidD2ArrowType is returned when an invalid D2 arrow type is provided.
var ErrInvalidD2Constraint = errors.New("invalid D2 constraint")
ErrInvalidD2Constraint is returned when an invalid D2 constraint is provided.
var ErrInvalidD2Direction = errors.New("invalid D2 direction")
ErrInvalidD2Direction is returned when an invalid D2 direction is provided.
var ErrInvalidD2NodeShape = errors.New("invalid D2 node shape")
ErrInvalidD2NodeShape is returned when an invalid D2 node shape is provided.
var ErrInvalidGraphShape = errors.New("invalid graph shape")
ErrInvalidGraphShape is returned when an invalid graph shape is provided.
var ErrInvalidSortBy = errors.New("invalid sort by")
ErrInvalidSortBy is returned when an invalid sort field is provided.
var ErrNoRendererRegistered = errors.New("no renderer registered for format")
ErrNoRendererRegistered is returned when no renderer is registered for a format.
var ErrUnsupportedType = errors.New("unsupported type")
ErrUnsupportedType is returned when an unsupported type is provided for TSV marshaling.
Functions ¶
func AddTreeNodes ¶
func AddTreeNodes( nodes *[]GraphNode, edges *[]GraphEdge, node *TreeNode, parentID string, idFunc TreeNodeIDFunc, shape GraphShape, )
AddTreeNodes recursively adds tree nodes and edges to the provided graph slices.
func AssertTreeNodeDepth ¶
AssertTreeNodeDepth verifies the depth of tree nodes in a hierarchy.
func DefaultGraphNodeLabel ¶
DefaultGraphNodeLabel returns a label in the format "header: cell".
func FilledStrings ¶
FilledStrings returns a slice of n strings, each filled with the given value.
func IsRegistered ¶
IsRegistered returns true if a format has a registered renderer.
func MarshalJSONIndent ¶
MarshalJSONIndent encodes v to indented JSON.
func MarshalXMLFromTableData ¶
MarshalXMLFromTableData marshals TableData to XML.
func MarshalXMLIndent ¶
MarshalXMLIndent encodes v to indented XML.
func MustRender ¶
MustRender calls Render on the provided Renderer and panics if it returns an error. Useful for tests and examples where rendering failure is unexpected.
func NewBrandedID ¶
NewBrandedID creates a new branded ID from a string value.
func Register ¶
func Register(format Format, factory RendererFactory) error
Register registers a renderer factory for a format.
func UnmarshalJSON ¶
UnmarshalJSON decodes JSON data into v.
func UnmarshalYAML ¶
UnmarshalYAML decodes YAML data into v.
Types ¶
type ASCIITreeRenderer ¶
type ASCIITreeRenderer struct {
// contains filtered or unexported fields
}
ASCIITreeRenderer implements the TreeOutputRenderer interface for ASCII tree output.
func NewASCIITreeRenderer ¶
func NewASCIITreeRenderer() *ASCIITreeRenderer
NewASCIITreeRenderer creates a new ASCIITreeRenderer.
func TreeRendererFromTableData ¶
func TreeRendererFromTableData(data *TableData) *ASCIITreeRenderer
TreeRendererFromTableData converts TableData to a tree using the first column as hierarchy.
func (*ASCIITreeRenderer) Render ¶
func (r *ASCIITreeRenderer) Render() (string, error)
Render returns the tree as a string.
func (*ASCIITreeRenderer) SetRoot ¶
func (r *ASCIITreeRenderer) SetRoot(node *TreeNode)
SetRoot sets the root node of the tree.
type Alignment ¶
type Alignment int
Alignment represents text alignment within a table cell.
const ( AlignLeft Alignment = AlignmentLeft AlignRight Alignment = AlignmentRight AlignCenter Alignment = AlignmentCenter )
Column alignment constants.
type BrandedID ¶
BrandedID re-export for backward compatibility. Use id.ID[Brand, string] for new code.
type CSVWriter ¶
type CSVWriter struct {
// contains filtered or unexported fields
}
CSVWriter writes CSV output.
func (*CSVWriter) WriteHeader ¶
WriteHeader writes the header row.
type ColorMode ¶
type ColorMode string
ColorMode controls terminal color output.
const ( ColorModeAuto ColorMode = "auto" ColorModeAlways ColorMode = "always" ColorModeNever ColorMode = "never" )
Terminal color output modes.
func ParseColorMode ¶
ParseColorMode converts a string to ColorMode, returning an error if invalid.
func (ColorMode) AllowedValues ¶
AllowedValues returns all valid color mode values.
func (ColorMode) ShouldColor ¶
ShouldColor returns true if colors should be enabled.
type D2ArrowType ¶
type D2ArrowType string
D2ArrowType represents the type of arrow for D2 edges.
const ( D2ArrowNone D2ArrowType = "" D2ArrowArrow D2ArrowType = "arrow" D2ArrowTriangle D2ArrowType = "triangle" D2ArrowDiamond D2ArrowType = "diamond" D2ArrowCircle D2ArrowType = "circle" D2ArrowFilled D2ArrowType = "filled" D2ArrowBox D2ArrowType = "box" D2ArrowCross D2ArrowType = "cross" D2ArrowCFOne D2ArrowType = "cf-one" D2ArrowCFMany D2ArrowType = "cf-many" D2ArrowCFOneRequired D2ArrowType = "cf-one-required" D2ArrowCFManyRequired D2ArrowType = "cf-many-required" )
D2ArrowType constants define the available arrow shapes for D2 edges.
func ParseD2ArrowType ¶
func ParseD2ArrowType(s string) (D2ArrowType, error)
ParseD2ArrowType converts a string to D2ArrowType, returning an error if invalid.
func (D2ArrowType) AllowedValues ¶
func (a D2ArrowType) AllowedValues() []string
AllowedValues returns all valid D2 arrow type values for CLI help text.
func (D2ArrowType) IsValid ¶
func (a D2ArrowType) IsValid() bool
IsValid returns true if the arrow type is a valid D2ArrowType value.
func (D2ArrowType) String ¶
func (a D2ArrowType) String() string
String returns the string representation of the arrow type.
type D2Column ¶
type D2Column struct {
Name string
Type string
Constraint D2Constraint
}
D2Column represents a column in a D2 SQL table shape.
type D2Constraint ¶
type D2Constraint string
D2Constraint represents a SQL constraint on a table column.
const ( D2ConstraintPrimary D2Constraint = "primary_key" D2ConstraintForeign D2Constraint = "foreign_key" D2ConstraintUnique D2Constraint = "unique" )
D2Constraint constants define the available SQL constraints for D2 table columns.
func AllD2Constraints ¶
func AllD2Constraints() []D2Constraint
AllD2Constraints returns all valid D2Constraint values.
func ParseD2Constraint ¶
func ParseD2Constraint(s string) (D2Constraint, error)
ParseD2Constraint converts a string to D2Constraint, returning an error if invalid.
func (D2Constraint) AllowedValues ¶
func (c D2Constraint) AllowedValues() []string
AllowedValues returns all valid D2Constraint values for CLI help text.
func (D2Constraint) IsValid ¶
func (c D2Constraint) IsValid() bool
IsValid returns true if the constraint is a valid D2Constraint value.
func (D2Constraint) String ¶
func (c D2Constraint) String() string
String returns the string representation of the constraint.
type D2Diagram ¶
type D2Diagram struct {
// contains filtered or unexported fields
}
D2Diagram builds D2 diagram output with full support for nodes, edges, SQL table shapes, styling, nesting, icons, links, tooltips, classes, and layout configuration.
func D2FromTableData ¶
D2FromTableData converts TableData to a D2 diagram with per-row nodes connected by edges.
func D2FromTree ¶
D2FromTree converts a TreeNode hierarchy to a D2 diagram.
func (*D2Diagram) AddClass ¶
func (d *D2Diagram) AddClass(name string, style D2NodeStyle) *D2Diagram
AddClass adds a reusable style class that can be referenced by nodes.
func (*D2Diagram) AddEdgeSimple ¶
AddEdgeSimple adds a simple edge between two nodes.
func (*D2Diagram) AddLabeledEdge ¶
AddLabeledEdge adds an edge with a label.
func (*D2Diagram) AddNodeSimple ¶
AddNodeSimple adds a simple node with just ID and label.
func (*D2Diagram) AddNodeWithShape ¶
func (d *D2Diagram) AddNodeWithShape(id, label string, shape D2NodeShape) *D2Diagram
AddNodeWithShape adds a node with a specific shape.
func (*D2Diagram) SetDirection ¶
func (d *D2Diagram) SetDirection(dir D2Direction) *D2Diagram
SetDirection sets the layout direction for the diagram.
func (*D2Diagram) SetEdges ¶
SetEdges sets graph edges from the generic GraphEdge type, satisfying GraphRenderer.
type D2Direction ¶
type D2Direction string
D2Direction constants for diagram layout direction.
const ( D2DirDown D2Direction = "" D2DirRight D2Direction = "right" D2DirLeft D2Direction = "left" D2DirUp D2Direction = "up" )
D2 direction constants.
func ParseD2Direction ¶
func ParseD2Direction(s string) (D2Direction, error)
ParseD2Direction converts a string to D2Direction, returning an error if invalid.
func (D2Direction) AllowedValues ¶
func (d D2Direction) AllowedValues() []string
AllowedValues returns all valid D2 direction values for CLI help text.
func (D2Direction) IsValid ¶
func (d D2Direction) IsValid() bool
IsValid returns true if the direction is a valid D2Direction value.
func (D2Direction) String ¶
func (d D2Direction) String() string
String returns the string representation of the direction.
type D2Edge ¶
type D2Edge struct {
From D2NodeID
To D2NodeID
Label D2NodeLabel
Style D2EdgeStyle
SourceArrow D2ArrowType
TargetArrow D2ArrowType
}
D2Edge represents an edge in a D2 diagram.
type D2EdgeStyle ¶
type D2EdgeStyle struct {
Stroke string
StrokeWidth int
StrokeDash int
Animated bool
FontColor string
FontSize int
}
D2EdgeStyle represents styling for a D2 edge.
type D2Node ¶
type D2Node struct {
ID D2NodeID
Label D2NodeLabel
Shape D2NodeShape
Style D2NodeStyle
Icon string
Link string
Tooltip string
Class string
Near string
Width int
Height int
GridRows int
GridColumns int
GridGap int
Nested string
}
D2Node represents a node in a D2 diagram.
type D2NodeID ¶
type D2NodeID = id.ID[D2NodeIDBrand, string]
D2NodeID is a branded identifier for D2 diagram nodes.
type D2NodeLabel ¶
type D2NodeLabel = id.ID[D2NodeLabelBrand, string]
D2NodeLabel is a branded identifier for D2 diagram node labels.
type D2NodeLabelBrand ¶
type D2NodeLabelBrand struct{}
D2NodeLabelBrand is the brand type for D2 node labels.
type D2NodeShape ¶
type D2NodeShape string
D2NodeShape represents the shape of a D2 node.
const ( D2ShapeRectangle D2NodeShape = "rectangle" D2ShapeSquare D2NodeShape = "square" D2ShapeCircle D2NodeShape = "circle" D2ShapeDiamond D2NodeShape = "diamond" D2ShapeHexagon D2NodeShape = "hexagon" D2ShapeCloud D2NodeShape = "cloud" D2ShapeCylinder D2NodeShape = "cylinder" D2ShapePerson D2NodeShape = "person" D2ShapeQueue D2NodeShape = "queue" D2ShapeOval D2NodeShape = "oval" D2ShapeParallelogram D2NodeShape = "parallelogram" D2ShapeTriangle D2NodeShape = "triangle" D2ShapeSQLTable D2NodeShape = "sql_table" D2ShapeImage D2NodeShape = "image" D2ShapeCode D2NodeShape = "code" D2ShapeText D2NodeShape = "text" D2ShapeClass D2NodeShape = "class" D2ShapePage D2NodeShape = "page" D2ShapeStep D2NodeShape = "step" D2ShapeStoredData D2NodeShape = "stored_data" )
D2NodeShape constants define the available shapes for D2 nodes.
func ParseD2NodeShape ¶
func ParseD2NodeShape(s string) (D2NodeShape, error)
ParseD2NodeShape converts a string to D2NodeShape, returning an error if invalid.
func (D2NodeShape) AllowedValues ¶
func (s D2NodeShape) AllowedValues() []string
AllowedValues returns all valid D2 node shape values for CLI help text.
func (D2NodeShape) IsValid ¶
func (s D2NodeShape) IsValid() bool
IsValid returns true if the shape is a valid D2NodeShape value.
func (D2NodeShape) String ¶
func (s D2NodeShape) String() string
String returns the string representation of the node shape.
type D2NodeStyle ¶
type D2NodeStyle struct {
Fill string
Stroke string
StrokeWidth int
StrokeDash int
FontSize int
FontColor string
Opacity float64
Shadow bool
BorderRadius int
TextTransform string
}
D2NodeStyle represents styling for a D2 node.
type DOTRenderer ¶
type DOTRenderer struct {
GraphRendererMixin
// contains filtered or unexported fields
}
DOTRenderer implements the GraphRenderer interface for DOT/Graphviz output.
func DOTFromTableData ¶
func DOTFromTableData(data *TableData) *DOTRenderer
DOTFromTableData converts TableData to a DOT graph.
func DOTFromTree ¶
func DOTFromTree(root *TreeNode) *DOTRenderer
DOTFromTree converts a TreeNode to DOT format.
func NewDOTRenderer ¶
func NewDOTRenderer() *DOTRenderer
NewDOTRenderer creates a new DOTRenderer for directed graphs.
func NewUndirectedDOTRenderer ¶
func NewUndirectedDOTRenderer() *DOTRenderer
NewUndirectedDOTRenderer creates a new DOTRenderer for undirected graphs.
func (*DOTRenderer) Render ¶
func (r *DOTRenderer) Render() (string, error)
Render returns the DOT graph as a string.
func (*DOTRenderer) SetGraphID ¶
func (r *DOTRenderer) SetGraphID(id string)
SetGraphID sets the graph ID.
type DelimitedWriter ¶
type DelimitedWriter struct {
// contains filtered or unexported fields
}
DelimitedWriter handles common logic for CSV and TSV writing.
func NewDelimitedWriter ¶
func NewDelimitedWriter(w io.Writer, delimiter rune, name string) *DelimitedWriter
NewDelimitedWriter creates a new DelimitedWriter.
func (*DelimitedWriter) Error ¶
func (d *DelimitedWriter) Error() error
Error returns any error encountered during writing.
type EdgeStyle ¶
type EdgeStyle struct {
Color string
Style string // solid, dashed, dotted
ArrowHead string
ArrowTail string
}
EdgeStyle represents styling attributes for an edge.
type ExpectedOutput ¶
type ExpectedOutput = gentest.ExpectedOutput
Re-export generic helpers from gentest for use by package output tests. This avoids code duplication while maintaining the unexported API.
type Format ¶
type Format string
Format represents the available output format options for CLI applications.
const ( FormatTable Format = "table" FormatJSON Format = "json" FormatCSV Format = "csv" FormatTSV Format = "tsv" FormatMarkdown Format = "markdown" FormatXML Format = "xml" FormatD2 Format = "d2" FormatYAML Format = "yaml" FormatHTML Format = "html" FormatTree Format = "tree" FormatMermaid Format = "mermaid" FormatDOT Format = "dot" )
Output format constants.
func ParseFormat ¶
ParseFormat converts a string to Format, returning an error if invalid.
func ParseOutputFormat ¶
ParseOutputFormat is a backward compatibility function that calls ParseFormat.
func RegisteredFormats ¶
func RegisteredFormats() []Format
RegisteredFormats returns a sorted list of all registered formats.
func (Format) AllowedValues ¶
AllowedValues returns all valid output format values for CLI help text.
func (Format) Category ¶
func (f Format) Category() FormatCategory
Category returns the category of the format.
func (Format) IsGraphFormat ¶
IsGraphFormat returns true if this is a graph/diagram format.
func (Format) IsTableFormat ¶
IsTableFormat returns true if this is a table-based format.
func (Format) IsTreeFormat ¶
IsTreeFormat returns true if this is a tree-based format.
type FormatCategory ¶
type FormatCategory int
FormatCategory represents a category for format classification.
const ( CategoryTable FormatCategory = iota CategoryTree CategoryGraph )
Format category constants for classifying output formats.
func (FormatCategory) String ¶
func (c FormatCategory) String() string
String returns the string representation of the format category.
type GraphEdge ¶
type GraphEdge struct {
From GraphNodeID
To GraphNodeID
Label GraphNodeLabel
Style EdgeStyle
}
GraphEdge represents an edge between two nodes.
func NewGraphEdge ¶
NewGraphEdge creates a new GraphEdge.
type GraphNode ¶
type GraphNode struct {
ID GraphNodeID
Label GraphNodeLabel
Shape GraphShape
Style GraphStyle
Metadata map[string]string
}
GraphNode represents a node in a graph.
func NewGraphNode ¶
NewGraphNode creates a new GraphNode.
func NodesFromTableData ¶
func NodesFromTableData(data *TableData, labelFn GraphNodeLabelFunc) []GraphNode
NodesFromTableData creates GraphNodes from TableData using the provided label function.
type GraphNodeID ¶
type GraphNodeID = id.ID[GraphNodeIDBrand, string]
GraphNodeID is a branded identifier for graph nodes.
type GraphNodeIDBrand ¶
type GraphNodeIDBrand struct{}
GraphNodeIDBrand is the brand type for graph node IDs.
type GraphNodeLabel ¶
type GraphNodeLabel = id.ID[GraphNodeLabelBrand, string]
GraphNodeLabel is a branded identifier for graph node labels.
type GraphNodeLabelBrand ¶
type GraphNodeLabelBrand struct{}
GraphNodeLabelBrand is the brand type for graph node labels.
type GraphNodeLabelFunc ¶
GraphNodeLabelFunc is a function that formats a cell value with its header into a label.
type GraphRenderer ¶
type GraphRenderer interface {
Renderer
// SetNodes sets the graph nodes.
SetNodes(nodes []GraphNode)
// SetEdges sets the graph edges.
SetEdges(edges []GraphEdge)
}
GraphRenderer defines the interface for graph format renderers.
type GraphRendererMixin ¶
type GraphRendererMixin struct {
// contains filtered or unexported fields
}
GraphRendererMixin contains shared fields and methods for graph renderers.
D2 does not use this mixin because it has richer domain-specific types (D2Node, D2Edge with classes, SQL tables, shapes, arrow types, etc.) that do not map to the simpler GraphNode/GraphEdge model.
func NewGraphRendererMixin ¶
func NewGraphRendererMixin() GraphRendererMixin
NewGraphRendererMixin creates a new GraphRendererMixin with initialized slices.
func (*GraphRendererMixin) AddRowEdges ¶
func (m *GraphRendererMixin) AddRowEdges(data *TableData)
AddRowEdges adds edges from data.CreateRowEdges() to the graph.
func (*GraphRendererMixin) SetEdges ¶
func (m *GraphRendererMixin) SetEdges(edges []GraphEdge)
SetEdges sets the graph edges.
func (*GraphRendererMixin) SetNodes ¶
func (m *GraphRendererMixin) SetNodes(nodes []GraphNode)
SetNodes sets the graph nodes.
func (*GraphRendererMixin) SetNodesFromTableData ¶
func (m *GraphRendererMixin) SetNodesFromTableData( data *TableData, modifyNode func(i int, n *GraphNode), )
SetNodesFromTableData creates nodes from TableData, applies per-node modifications, adds them to the graph, and adds row edges.
type GraphShape ¶
type GraphShape string
GraphShape represents the shape of a graph node.
const ( ShapeBox GraphShape = "box" ShapeEllipse GraphShape = "ellipse" ShapeDiamond GraphShape = "diamond" ShapeCircle GraphShape = "circle" ShapeCylinder GraphShape = "cylinder" ShapeHexagon GraphShape = "hexagon" ShapeParallelogram GraphShape = "parallelogram" ShapeRect GraphShape = "rect" )
GraphShape constants define the available shapes for graph nodes.
func ParseGraphShape ¶
func ParseGraphShape(s string) (GraphShape, error)
ParseGraphShape converts a string to GraphShape, returning an error if invalid.
func (GraphShape) AllowedValues ¶
func (s GraphShape) AllowedValues() []string
AllowedValues returns all valid graph shape values.
func (GraphShape) IsValid ¶
func (s GraphShape) IsValid() bool
IsValid checks if the graph shape is valid.
func (GraphShape) String ¶
func (s GraphShape) String() string
String returns the string representation of the graph shape.
type GraphStyle ¶
GraphStyle represents styling attributes for a graph node.
type HTMLRenderer ¶
type HTMLRenderer struct {
// contains filtered or unexported fields
}
HTMLRenderer implements the Renderer interface for HTML table output.
func NewHTMLRenderer ¶
func NewHTMLRenderer() *HTMLRenderer
NewHTMLRenderer creates a new HTMLRenderer.
func (*HTMLRenderer) Render ¶
func (r *HTMLRenderer) Render() (string, error)
Render returns the HTML table as a string.
func (*HTMLRenderer) RenderFullHTML ¶
func (r *HTMLRenderer) RenderFullHTML(title string) (string, error)
RenderFullHTML returns a complete HTML document with the table.
func (*HTMLRenderer) SetData ¶
func (b *HTMLRenderer) SetData(data *TableData)
SetData sets the table data directly.
func (*HTMLRenderer) SetHeaders ¶
func (b *HTMLRenderer) SetHeaders(headers []string)
SetHeaders sets the column headers.
type HTMLTreeRenderer ¶
type HTMLTreeRenderer struct {
// contains filtered or unexported fields
}
HTMLTreeRenderer renders a tree structure as HTML with nested lists.
func NewHTMLTreeRenderer ¶
func NewHTMLTreeRenderer() *HTMLTreeRenderer
NewHTMLTreeRenderer creates a new HTMLTreeRenderer.
func (*HTMLTreeRenderer) Render ¶
func (r *HTMLTreeRenderer) Render() (string, error)
Render returns the tree as an HTML string.
func (*HTMLTreeRenderer) RenderFullHTML ¶
func (r *HTMLTreeRenderer) RenderFullHTML(title string) (string, error)
RenderFullHTML returns a complete HTML document with the tree.
func (*HTMLTreeRenderer) SetRoot ¶
func (r *HTMLTreeRenderer) SetRoot(node *TreeNode)
SetRoot sets the root node of the tree.
type InvalidFormatError ¶
InvalidFormatError represents an invalid format error.
func (*InvalidFormatError) Error ¶
func (e *InvalidFormatError) Error() string
Error returns a descriptive error message including allowed values.
type JSONWriter ¶
JSONWriter writes JSON output to an io.Writer.
func NewJSONWriter ¶
func NewJSONWriter(w io.Writer) *JSONWriter
NewJSONWriter creates a new JSONWriter.
func (*JSONWriter) Encode ¶
func (j *JSONWriter) Encode(v any) error
Encode writes v as JSON to the underlying writer.
type MarkdownTable ¶
type MarkdownTable struct {
// contains filtered or unexported fields
}
MarkdownTable builds Markdown tables.
func NewMarkdownTable ¶
func NewMarkdownTable() *MarkdownTable
NewMarkdownTable creates a new MarkdownTable.
func NewMarkdownTableFromData ¶
func NewMarkdownTableFromData(data *TableData) *MarkdownTable
NewMarkdownTableFromData creates a MarkdownTable populated from TableData.
func (*MarkdownTable) AddRow ¶
func (m *MarkdownTable) AddRow(row []string) *MarkdownTable
AddRow adds a row to the table.
func (*MarkdownTable) Render ¶
func (m *MarkdownTable) Render() (string, error)
Render returns the Markdown table string.
func (*MarkdownTable) SetAlign ¶
func (m *MarkdownTable) SetAlign(col int, alignment Alignment) *MarkdownTable
SetAlign sets column alignment.
func (*MarkdownTable) SetHeaders ¶
func (m *MarkdownTable) SetHeaders(headers []string) *MarkdownTable
SetHeaders sets the table headers.
type MermaidRenderer ¶
type MermaidRenderer struct {
GraphRendererMixin
}
MermaidRenderer implements the GraphRenderer interface for Mermaid diagrams.
func MermaidFlowchartRenderer ¶
func MermaidFlowchartRenderer(data *TableData) *MermaidRenderer
MermaidFlowchartRenderer creates a Mermaid flowchart from table data.
func MermaidTreeRenderer ¶
func MermaidTreeRenderer(root *TreeNode) *MermaidRenderer
MermaidTreeRenderer converts a TreeNode to Mermaid.
func NewMermaidRenderer ¶
func NewMermaidRenderer() *MermaidRenderer
NewMermaidRenderer creates a new MermaidRenderer.
func (*MermaidRenderer) Render ¶
func (r *MermaidRenderer) Render() (string, error)
Render returns the Mermaid diagram as a string.
type OutputFormat
deprecated
type OutputFormat = Format
OutputFormat is a backward compatibility alias for Format.
Deprecated: Use Format directly instead of OutputFormat.
type Renderer ¶
type Renderer interface {
// Render returns the formatted output as a string.
Render() (string, error)
}
Renderer defines the interface for output format renderers.
type RendererFactory ¶
type RendererFactory func() Renderer
RendererFactory is a function that creates a Renderer instance.
type SortBy ¶
type SortBy string
SortBy represents the available sort field options for CLI applications.
const ( SortByName SortBy = "name" SortByImportance SortBy = "importance" SortByCreatedAt SortBy = "created_at" SortByUpdatedAt SortBy = "updated_at" SortByHealth SortBy = "health" SortByComplexity SortBy = "complexity" )
Sort field constants.
func ParseSortBy ¶
ParseSortBy converts a string to SortBy, returning an error if invalid.
func (SortBy) AllowedValues ¶
AllowedValues returns all valid sort field values for CLI help text.
type StreamingHTMLRenderer ¶
type StreamingHTMLRenderer struct {
// contains filtered or unexported fields
}
StreamingHTMLRenderer is a streaming implementation of HTMLRenderer. It writes output incrementally to minimize memory usage.
func NewStreamingHTMLRenderer ¶
func NewStreamingHTMLRenderer() *StreamingHTMLRenderer
NewStreamingHTMLRenderer creates a new StreamingHTMLRenderer.
func (*StreamingHTMLRenderer) AddRow ¶
func (b *StreamingHTMLRenderer) AddRow(row []string)
AddRow adds a data row.
func (*StreamingHTMLRenderer) Render ¶
func (r *StreamingHTMLRenderer) Render() (string, error)
Render returns the HTML table as a string.
func (*StreamingHTMLRenderer) SetData ¶
func (b *StreamingHTMLRenderer) SetData(data *TableData)
SetData sets the table data directly.
func (*StreamingHTMLRenderer) SetHeaders ¶
func (b *StreamingHTMLRenderer) SetHeaders(headers []string)
SetHeaders sets the column headers.
type StreamingRenderer ¶
type StreamingRenderer interface {
Renderer
// Stream writes the rendered output to an io.Writer in chunks.
Stream(w io.Writer) error
}
StreamingRenderer is an interface for renderers that support streaming output. This is useful for rendering large datasets without loading everything into memory.
Note: Not all implementations provide true streaming. The adapter returned by StreamingRendererFromRenderer collects output before writing. Only StreamingHTMLRenderer provides genuine streaming behavior.
func StreamingRendererFromRenderer ¶
func StreamingRendererFromRenderer(r Renderer) StreamingRenderer
StreamingRendererFromRenderer wraps a standard Renderer to implement StreamingRenderer. Note: This adapter does not provide true streaming behavior - it collects all output via Render() and then writes it at once. It exists to satisfy the StreamingRenderer interface for renderers that don't have native streaming support.
type TSVWriter ¶
type TSVWriter struct {
// contains filtered or unexported fields
}
TSVWriter writes TSV (Tab-Separated Values) output.
func (*TSVWriter) WriteHeader ¶
WriteHeader writes the header row.
type TableData ¶
TableData represents tabular data with headers and rows.
func NewTableData ¶
NewTableData creates a new TableData with the given headers.
func (*TableData) CreateRowEdges ¶
CreateRowEdges generates edge data connecting consecutive rows. Used by graph renderers to create edges between table rows.
func (*TableData) GetHeaders ¶
GetHeaders returns the column headers. Satisfies the table.TableDataProvider interface.
type TableRenderer ¶
type TableRenderer interface {
Renderer
// SetHeaders sets the column headers.
SetHeaders(headers []string)
// AddRow adds a data row.
AddRow(row []string)
}
TableRenderer defines the interface for table format renderers.
type TreeNode ¶
type TreeNode struct {
ID TreeNodeID
Label TreeNodeLabel
Children []*TreeNode
Metadata map[string]string
// contains filtered or unexported fields
}
TreeNode represents a node in a tree structure.
func NewTreeNode ¶
NewTreeNode creates a new TreeNode with the given ID and label.
type TreeNodeID ¶
type TreeNodeID = id.ID[TreeNodeIDBrand, string]
TreeNodeID is a branded identifier for tree nodes.
type TreeNodeIDBrand ¶
type TreeNodeIDBrand struct{}
TreeNodeIDBrand is the brand type for tree node IDs.
type TreeNodeIDFunc ¶
TreeNodeIDFunc resolves a TreeNode's ID for a specific graph format.
type TreeNodeLabel ¶
type TreeNodeLabel = id.ID[TreeNodeLabelBrand, string]
TreeNodeLabel is a branded identifier for tree node labels.
type TreeNodeLabelBrand ¶
type TreeNodeLabelBrand struct{}
TreeNodeLabelBrand is the brand type for tree node labels.
type TreeOutputRenderer ¶
type TreeOutputRenderer interface {
Renderer
// SetRoot sets the root node of the tree.
SetRoot(node *TreeNode)
}
TreeOutputRenderer defines the interface for tree format renderers.
type XMLWriter ¶
XMLWriter writes XML output to an io.Writer.
func (*XMLWriter) WriteFooter ¶
WriteFooter writes the closing tags.
func (*XMLWriter) WriteHeader ¶
WriteHeader writes the XML header and opening tags.