Documentation
¶
Overview ¶
Package output provides consistent output formatting for CLI applications.
Package output provides consistent output formatting for CLI applications.
Index ¶
- Variables
- func AddTreeNodes(nodes *[]GraphNode, edges *[]GraphEdge, node *TreeNode, parentID string, ...)
- func DefaultGraphNodeLabel(header, cell string) string
- func FilledStrings(n int, value string) []string
- func IsRegistered(format Format) booldeprecated
- func MarshalCSVFromTableData(data *TableData) ([]byte, error)
- func MarshalJSON(v any) ([]byte, error)
- func MarshalJSONIndent(v any, prefix, indent string) ([]byte, error)
- func MarshalTSV(data any) ([]byte, error)
- func MarshalTSVFromTableData(data *TableData) ([]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) errordeprecated
- func RenderTableData(data *TableData, format Format, opts ...RenderOptions) error
- func UnmarshalJSON(data []byte, v any) error
- func UnmarshalYAML(data []byte, v any) error
- func Unregister(format Format)deprecated
- type ASCIITreeRenderer
- type Alignment
- type BrandedID
- type CSVWriter
- type ColorMode
- type D2NodeID
- type D2NodeIDBrand
- type D2NodeLabel
- type D2NodeLabelBrand
- type DelimitedWriter
- type EdgeStyle
- type Format
- type GraphEdge
- type GraphNode
- type GraphNodeID
- type GraphNodeIDBrand
- type GraphNodeLabel
- type GraphNodeLabelBrand
- type GraphNodeLabelFunc
- type GraphRenderer
- type GraphRendererMixin
- func (m *GraphRendererMixin) AddRowEdges(data *TableData)
- func (m *GraphRendererMixin) Edges() []GraphEdge
- func (m *GraphRendererMixin) EdgesPtr() *[]GraphEdge
- func (m *GraphRendererMixin) Nodes() []GraphNode
- func (m *GraphRendererMixin) NodesPtr() *[]GraphNode
- func (m *GraphRendererMixin) SetEdges(edges []GraphEdge)
- func (m *GraphRendererMixin) SetNodes(nodes []GraphNode)
- func (m *GraphRendererMixin) SetNodesFromTableData(data *TableData, modifyNode func(i int, n *GraphNode))
- type GraphShape
- type GraphStyle
- type HTMLRenderer
- type HTMLTreeRenderer
- type InvalidColorModeError
- type InvalidFormatError
- type InvalidGraphShapeError
- type InvalidShapeError
- type InvalidSortByError
- type JSONGraphRenderer
- type JSONTableRenderer
- type JSONTreeRenderer
- type JSONWriter
- type MarkdownTable
- type RenderOptions
- type Renderer
- type RendererFactory
- type RowEdge
- type Shape
- type SortBydeprecated
- 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 UnsupportedFormatError
- type XMLWriter
- type YAMLGraphRenderer
- type YAMLTableRenderer
- type YAMLTreeRenderer
Constants ¶
This section is empty.
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 AllShapes = []Shape{ ShapeTable, ShapeTree, ShapeGraph, }
AllShapes contains all valid data shape values.
var ErrFormatAlreadyRegistered = errors.New("format already registered")
ErrFormatAlreadyRegistered is returned when a format is already registered.
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 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
deprecated
func MarshalCSVFromTableData ¶ added in v0.5.0
MarshalCSVFromTableData marshals TableData as CSV with a header row.
func MarshalJSONIndent ¶
MarshalJSONIndent encodes v to indented JSON.
func MarshalTSVFromTableData ¶ added in v0.5.0
MarshalTSVFromTableData marshals TableData as TSV with a header row.
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
deprecated
func Register(format Format, factory RendererFactory) error
Register registers a renderer factory for a format.
Deprecated: Use format constructors directly. This function may be removed in a future version.
func RenderTableData ¶ added in v0.5.0
func RenderTableData(data *TableData, format Format, opts ...RenderOptions) error
RenderTableData renders TableData in the given format and writes to w (or os.Stdout). It supports: csv, tsv, markdown, xml, yaml, html, tree.
D2, Mermaid, and DOT are NOT handled — those require importing the d2 or graph sub-modules directly. Table and JSON formats also require per-command customization (table for lipgloss styling, json for full struct marshaling).
Returns UnsupportedFormatError for unsupported formats (d2, mermaid, dot, table, json).
func UnmarshalJSON ¶
UnmarshalJSON decodes JSON data into v.
func UnmarshalYAML ¶
UnmarshalYAML decodes YAML data into v.
func Unregister
deprecated
func Unregister(format Format)
Unregister removes a format from the registry.
Deprecated: Use format constructors directly.
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 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 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 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 FormatsForShape ¶ added in v0.5.0
FormatsForShape returns all formats that support the given data shape.
func ParseFormat ¶
ParseFormat converts a string to Format, returning an error if invalid.
func RegisteredFormats
deprecated
func RegisteredFormats() []Format
RegisteredFormats returns a sorted list of all registered formats.
Deprecated: Use format constructors directly.
func (Format) AllowedValues ¶
AllowedValues returns all valid output format values for CLI help text.
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) Edges ¶ added in v0.5.0
func (m *GraphRendererMixin) Edges() []GraphEdge
Edges returns the graph edges.
func (*GraphRendererMixin) EdgesPtr ¶ added in v0.5.0
func (m *GraphRendererMixin) EdgesPtr() *[]GraphEdge
EdgesPtr returns a pointer to the graph edges slice for mutation.
func (*GraphRendererMixin) Nodes ¶ added in v0.5.0
func (m *GraphRendererMixin) Nodes() []GraphNode
Nodes returns the graph nodes.
func (*GraphRendererMixin) NodesPtr ¶ added in v0.5.0
func (m *GraphRendererMixin) NodesPtr() *[]GraphNode
NodesPtr returns a pointer to the graph nodes slice for mutation.
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 InvalidColorModeError ¶ added in v0.5.0
type InvalidColorModeError struct {
Value string
}
InvalidColorModeError is returned when an invalid color mode is provided.
func (*InvalidColorModeError) Error ¶ added in v0.5.0
func (e *InvalidColorModeError) Error() string
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 InvalidGraphShapeError ¶ added in v0.5.0
type InvalidGraphShapeError struct {
Value string
}
InvalidGraphShapeError is returned when an invalid graph shape is provided.
func (*InvalidGraphShapeError) Error ¶ added in v0.5.0
func (e *InvalidGraphShapeError) Error() string
type InvalidShapeError ¶ added in v0.5.0
type InvalidShapeError struct {
Value string
}
InvalidShapeError is returned when an invalid data shape is provided.
func (*InvalidShapeError) Error ¶ added in v0.5.0
func (e *InvalidShapeError) Error() string
type InvalidSortByError ¶ added in v0.5.0
type InvalidSortByError struct {
Value string
}
InvalidSortByError is returned when an invalid sort field is provided.
func (*InvalidSortByError) Error ¶ added in v0.5.0
func (e *InvalidSortByError) Error() string
type JSONGraphRenderer ¶ added in v0.5.0
type JSONGraphRenderer struct {
GraphRendererMixin
}
JSONGraphRenderer renders graph nodes and edges as JSON.
func NewJSONGraphRenderer ¶ added in v0.5.0
func NewJSONGraphRenderer() *JSONGraphRenderer
NewJSONGraphRenderer creates a new JSONGraphRenderer.
func (*JSONGraphRenderer) Render ¶ added in v0.5.0
func (r *JSONGraphRenderer) Render() (string, error)
Render returns the graph as a JSON string.
type JSONTableRenderer ¶ added in v0.5.0
type JSONTableRenderer struct {
// contains filtered or unexported fields
}
JSONTableRenderer renders TableData as a JSON array of objects. Each row becomes a JSON object with headers as keys.
func NewJSONTableRenderer ¶ added in v0.5.0
func NewJSONTableRenderer() *JSONTableRenderer
NewJSONTableRenderer creates a new JSONTableRenderer.
func (*JSONTableRenderer) AddRow ¶ added in v0.5.0
func (b *JSONTableRenderer) AddRow(row []string)
AddRow adds a data row.
func (*JSONTableRenderer) Render ¶ added in v0.5.0
func (r *JSONTableRenderer) Render() (string, error)
Render returns the table data as a JSON string.
func (*JSONTableRenderer) SetData ¶ added in v0.5.0
func (b *JSONTableRenderer) SetData(data *TableData)
SetData sets the table data directly.
func (*JSONTableRenderer) SetHeaders ¶ added in v0.5.0
func (b *JSONTableRenderer) SetHeaders(headers []string)
SetHeaders sets the column headers.
type JSONTreeRenderer ¶ added in v0.5.0
type JSONTreeRenderer struct {
// contains filtered or unexported fields
}
JSONTreeRenderer renders a TreeNode hierarchy as JSON. Each node becomes a JSON object with "id", "label", and optional "children".
func NewJSONTreeRenderer ¶ added in v0.5.0
func NewJSONTreeRenderer() *JSONTreeRenderer
NewJSONTreeRenderer creates a new JSONTreeRenderer.
func (*JSONTreeRenderer) Render ¶ added in v0.5.0
func (r *JSONTreeRenderer) Render() (string, error)
Render returns the tree as a JSON string.
func (*JSONTreeRenderer) SetRoot ¶ added in v0.5.0
func (r *JSONTreeRenderer) SetRoot(node *TreeNode)
SetRoot sets the root node of the tree.
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 RenderOptions ¶ added in v0.5.0
type RenderOptions struct {
// Title is used as the document title for HTML output and as a header for Markdown.
Title string
// GraphID is used as the graph identifier for DOT output.
GraphID string
// Writer overrides the default os.Stdout output destination.
Writer io.Writer
}
RenderOptions configures optional behavior for RenderTableData.
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 Shape ¶ added in v0.5.0
type Shape string
Shape represents a data shape that a format can render.
const ( ShapeTable Shape = "table" // Tabular data with headers and rows ShapeTree Shape = "tree" // Hierarchical data with parent-child nodes ShapeGraph Shape = "graph" // Network data with nodes and edges )
Data shape constants for format capability classification.
func ParseShape ¶ added in v0.5.0
ParseShape converts a string to Shape, returning an error if invalid.
func (Shape) AllowedValues ¶ added in v0.5.0
AllowedValues returns all valid data shape values for CLI help text.
type SortBy
deprecated
type SortBy string
SortBy represents the available sort field options for CLI applications.
Deprecated: SortBy is application-specific business logic that does not belong in a general-purpose output library. Define your own sort enum in your application.
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.
func (*TableData) GetRows ¶
GetRows returns the data rows. Satisfies the table.TableDataProvider interface.
func (*TableData) ToMapSlice ¶ added in v0.5.0
ToMapSlice converts TableData to a slice of maps (header→cell). Returns nil if data is nil or has no headers.
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 UnsupportedFormatError ¶ added in v0.5.0
type UnsupportedFormatError struct {
Format Format
}
UnsupportedFormatError is returned when RenderTableData cannot handle a format.
func (*UnsupportedFormatError) Error ¶ added in v0.5.0
func (e *UnsupportedFormatError) Error() string
func (*UnsupportedFormatError) Unwrap ¶ added in v0.5.0
func (e *UnsupportedFormatError) Unwrap() error
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.
type YAMLGraphRenderer ¶ added in v0.5.0
type YAMLGraphRenderer struct {
GraphRendererMixin
}
YAMLGraphRenderer renders graph nodes and edges as YAML.
func NewYAMLGraphRenderer ¶ added in v0.5.0
func NewYAMLGraphRenderer() *YAMLGraphRenderer
NewYAMLGraphRenderer creates a new YAMLGraphRenderer.
func (*YAMLGraphRenderer) Render ¶ added in v0.5.0
func (r *YAMLGraphRenderer) Render() (string, error)
Render returns the graph as a YAML string.
type YAMLTableRenderer ¶ added in v0.5.0
type YAMLTableRenderer struct {
// contains filtered or unexported fields
}
YAMLTableRenderer renders TableData as a YAML sequence of mappings. Each row becomes a YAML map with headers as keys.
func NewYAMLTableRenderer ¶ added in v0.5.0
func NewYAMLTableRenderer() *YAMLTableRenderer
NewYAMLTableRenderer creates a new YAMLTableRenderer.
func (*YAMLTableRenderer) AddRow ¶ added in v0.5.0
func (b *YAMLTableRenderer) AddRow(row []string)
AddRow adds a data row.
func (*YAMLTableRenderer) Render ¶ added in v0.5.0
func (r *YAMLTableRenderer) Render() (string, error)
Render returns the table data as a YAML string.
func (*YAMLTableRenderer) SetData ¶ added in v0.5.0
func (b *YAMLTableRenderer) SetData(data *TableData)
SetData sets the table data directly.
func (*YAMLTableRenderer) SetHeaders ¶ added in v0.5.0
func (b *YAMLTableRenderer) SetHeaders(headers []string)
SetHeaders sets the column headers.
type YAMLTreeRenderer ¶ added in v0.5.0
type YAMLTreeRenderer struct {
// contains filtered or unexported fields
}
YAMLTreeRenderer renders a TreeNode hierarchy as YAML.
func NewYAMLTreeRenderer ¶ added in v0.5.0
func NewYAMLTreeRenderer() *YAMLTreeRenderer
NewYAMLTreeRenderer creates a new YAMLTreeRenderer.
func (*YAMLTreeRenderer) Render ¶ added in v0.5.0
func (r *YAMLTreeRenderer) Render() (string, error)
Render returns the tree as a YAML string.
func (*YAMLTreeRenderer) SetRoot ¶ added in v0.5.0
func (r *YAMLTreeRenderer) SetRoot(node *TreeNode)
SetRoot sets the root node of the tree.