Help us shape the future of Go! Take the 2026 Go Developer Survey

format

package
v1.233.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCSVDelimiter = ","
	DefaultTSVDelimiter = "\t"
	ValueKey            = "value"
)
View Source
const (
	MaxColumnWidth            = 60 // Maximum width for a column.
	TableColumnPadding        = 3  // Padding for table columns.
	DefaultKeyWidth           = 15 // Default base width for keys.
	KeyValue                  = "value"
	CompactColumnMaxWidth     = 20 // Maximum width for non-Description columns.
	DescriptionColumnMinWidth = 30 // Minimum width for Description column.
	MinColumnWidth            = 5  // Absolute minimum width for any column.

)

Constants for table formatting.

Variables

View Source
var (
	ErrTableTooWide = errors.New("the table is too wide to display properly")
)

Error variables for table formatting.

Functions

func CreateStyledTable added in v1.176.0

func CreateStyledTable(header []string, rows [][]string) string

CreateStyledTable creates a styled table with headers and rows. Uses intelligent column width calculation to optimize space usage.

func CreateStyledTableWithOptions added in v1.225.0

func CreateStyledTableWithOptions(header []string, rows [][]string, options TableOptions) string

CreateStyledTableWithOptions is CreateStyledTable with explicit behavior options.

func RenderDependenciesTree added in v1.222.0

func RenderDependenciesTree(entries []*DepTreeEntry) string

RenderDependenciesTree renders component dependencies as a tree.

func RenderInstancesTree added in v1.201.0

func RenderInstancesTree(stacksWithComponents map[string]map[string][]*listtree.ImportNode, showImports bool) string

RenderInstancesTree renders stacks with their components and import hierarchies as a tree. Structure: Stacks → Components → Imports. If showImports is false, only shows stacks and components without import details.

func RenderStacksTree added in v1.201.0

func RenderStacksTree(stacksWithImports map[string][]*listtree.ImportNode, showImports bool) string

RenderStacksTree renders stacks with their import hierarchies as a tree. If showImports is false, only stack names are shown without import details.

func ValidateFormat

func ValidateFormat(format string) error

ValidateFormat checks if the provided format is valid for the renderer pipeline. Note: tree and matrix are valid CLI formats but are handled as special cases before reaching the renderer, so they are not included here. Commands that support tree/matrix must check for them before calling ValidateFormat.

Types

type ColumnRole added in v1.225.0

type ColumnRole int

ColumnRole names a semantic per-column color treatment applied to every cell in the column regardless of its value. Unlike SemanticCellStyling (which colors a cell by its content — true/false, numbers, placeholders), a column role gives a table gentle positional contrast — e.g. a muted timestamp column next to an accented identifier column — without implying pass/fail semantics. Roles apply color only (Foreground); they never touch padding, width, or weight, so column-width math is unaffected.

const (
	// ColumnRoleNone applies no column-level override; the cell falls back to
	// the plain base style (and semantic styling, if enabled).
	ColumnRoleNone ColumnRole = iota
	// ColumnRoleMuted dims secondary or historical information (e.g. dates, past values).
	ColumnRoleMuted
	// ColumnRoleIdentifier accents identifiers/keys using the theme's command/primary color.
	ColumnRoleIdentifier
	// ColumnRoleAccent applies a subtle secondary accent for emphasized-but-not-alarming values.
	ColumnRoleAccent
)

type DefaultFormatter

type DefaultFormatter struct {
	// contains filtered or unexported fields
}

DefaultFormatter provides a base implementation of Formatter.

type DelimitedFormatter

type DelimitedFormatter struct {
	DefaultFormatter
	// contains filtered or unexported fields
}

DelimitedFormatter handles CSV and TSV format output.

func (*DelimitedFormatter) Format

func (f *DelimitedFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for DelimitedFormatter.

type DepTreeEntry added in v1.222.0

type DepTreeEntry struct {
	Component  string
	Stack      string
	Type       string
	DependsOn  []*DepTreeNode
	RequiredBy []*DepTreeNode
	ShowBoth   bool
}

DepTreeEntry is a top-level component in the dependency tree along with the direction subtrees to display. When only one of DependsOn/RequiredBy is populated, its children are rendered directly under the component (no group label). When both are populated, each is rendered under a labeled branch.

type DepTreeNode added in v1.222.0

type DepTreeNode struct {
	Component string
	Stack     string
	Type      string
	Optional  bool
	Circular  bool
	Children  []*DepTreeNode
}

DepTreeNode is a render-friendly node in a dependency subtree. Circular marks a node whose expansion was stopped because it was already on the current path.

type Format

type Format string

Format represents the output format type.

const (
	FormatTable    Format = "table"
	FormatJSON     Format = "json"
	FormatYAML     Format = "yaml"
	FormatCSV      Format = "csv"
	FormatTSV      Format = "tsv"
	FormatPaths    Format = "paths"
	FormatTemplate Format = "template"
	FormatTree     Format = "tree"
	FormatMatrix   Format = "matrix"
)

type FormatOptions

type FormatOptions struct {
	MaxColumns    int
	Delimiter     string
	TTY           bool
	Format        Format
	CustomHeaders []string
}

FormatOptions contains options for formatting output.

type Formatter

type Formatter interface {
	Format(data map[string]interface{}, options FormatOptions) (string, error)
}

Formatter defines the interface for formatting output.

func NewFormatter

func NewFormatter(format Format) (Formatter, error)

NewFormatter creates a new formatter for the specified format.

type JSONFormatter

type JSONFormatter struct {
	DefaultFormatter
}

JSONFormatter handles JSON format output.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for JSONFormatter.

type TableFormatter

type TableFormatter struct {
	DefaultFormatter
}

TableFormatter handles table format output.

func (*TableFormatter) Format

func (f *TableFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for TableFormatter.

type TableOptions added in v1.225.0

type TableOptions struct {
	// SemanticCellStyling colors cells by detected content type (booleans
	// green/red, numbers, placeholders). Disable it for tables whose values are
	// plain data rather than statuses, where the coloring reads as noise.
	SemanticCellStyling bool

	// ColumnRoles, when set, assigns a ColumnRole to each column by index
	// (aligned with the header slice). A shorter slice (or a nil entry) leaves
	// the remaining columns unstyled. When SemanticCellStyling is also enabled,
	// the column role becomes the base style that semantic content-type
	// coloring is layered on top of.
	ColumnRoles []ColumnRole
}

TableOptions controls optional styled-table behaviors.

type YAMLFormatter

type YAMLFormatter struct {
	DefaultFormatter
}

YAMLFormatter handles YAML format output.

func (*YAMLFormatter) Format

func (f *YAMLFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for YAMLFormatter.

Jump to

Keyboard shortcuts

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