Documentation
¶
Overview ¶
Package output provides output formatting for matter-cli commands. It supports table, JSON, and YAML formats with automatic TTY detection.
Index ¶
- Variables
- func Accent(s string) string
- func Bold(s string) string
- func Command(s string) string
- func Dim(s string) string
- func Error(s string) string
- func ErrorIcon() string
- func Flag(s string) string
- func FormatRichTree(w io.Writer, data *TreeData) error
- func FormatTree(w io.Writer, node *store.Node) error
- func Header(s string) string
- func Info(s string) string
- func InfoIcon() string
- func IsTTY() bool
- func Label(s string) string
- func Muted(s string) string
- func NoColor() bool
- func RenderQRCode(w io.Writer, payload string) bool
- func RenderTreeSVG(data *TreeData, filename string) error
- func SpinnerIcon() string
- func Success(s string) string
- func SuccessIcon() string
- func TermWidth() int
- func Value(s string) string
- func Warning(s string) string
- func WarningIcon() string
- type FormatType
- type Formatter
- type JSONFormatter
- type LogHandler
- type Stepper
- type TableData
- type TableFormatter
- type TreeAttribute
- type TreeCluster
- type TreeData
- type TreeEndpoint
Constants ¶
This section is empty.
Variables ¶
var ( // StyleSuccess renders text in green. StyleSuccess = lipgloss.NewStyle().Foreground(colorGreen) // StyleError renders text in red and bold. StyleError = lipgloss.NewStyle().Foreground(colorRed).Bold(true) // StyleWarning renders text in yellow. StyleWarning = lipgloss.NewStyle().Foreground(colorYellow) // StyleInfo renders text in blue. StyleInfo = lipgloss.NewStyle().Foreground(colorBlue) // StyleBold renders text in bold. StyleBold = lipgloss.NewStyle().Bold(true) // StyleDim renders text with reduced intensity using the terminal's own // faint/dim attribute (ANSI SGR 2) rather than a fixed gray color. StyleDim = lipgloss.NewStyle().Faint(true) // StyleLabel renders a key/label (e.g. "Vendor:") in cyan bold. StyleLabel = lipgloss.NewStyle().Foreground(colorCyan).Bold(true) // StyleValue renders a value in light gray (ANSI 7). StyleValue = lipgloss.NewStyle().Foreground(colorLightGray) // StyleAccent renders text in magenta (used for IDs, hex values). StyleAccent = lipgloss.NewStyle().Foreground(colorMagenta) // StyleHeader renders table/section headers in blue bold. StyleHeader = lipgloss.NewStyle().Foreground(colorBlue).Bold(true) // StyleMuted renders secondary/less-important text in ANSI color 8 // (Bright Black / Dark Gray). This is the canonical "comment" color across // terminal themes (Solarized, Nord, Dracula, Catppuccin, …) and gives a // reliably subdued appearance in both dark and light palettes, unlike the // faint attribute (SGR 2) which many terminals render inconsistently. StyleMuted = lipgloss.NewStyle().Foreground(colorGray) // StyleCommand renders command names in cyan. StyleCommand = lipgloss.NewStyle().Foreground(colorCyan) // StyleFlag renders flag names in yellow. StyleFlag = lipgloss.NewStyle().Foreground(colorYellow) )
Functions ¶
func FormatRichTree ¶
FormatRichTree renders the device tree with depth controlled by data.Level:
1 – endpoints only 2 – endpoints + clusters 3 – endpoints + clusters + attribute names 4 – endpoints + clusters + attribute names + values
On wide terminals endpoints are shown side-by-side: a branch bar fans out from the node and vertical drop lines connect down to each endpoint column. On narrow terminals or pipes the classic top-down tree is used instead.
func FormatTree ¶
FormatTree writes a tree-style representation of a node to w, showing endpoints, clusters, and device types.
func NoColor ¶
func NoColor() bool
NoColor reports whether the NO_COLOR environment variable is set.
func RenderQRCode ¶
RenderQRCode writes a scannable 2D QR code for payload to w using Unicode half-block characters (two QR modules per terminal cell). Returns false when no visual QR was emitted — callers may still want to print the textual code.
The QR uses error-correction level M (matches Matter controllers such as Apple Home / Google Home which also encode at level M) and includes the standard 4-module quiet zone so phone-camera commissioners can lock onto it.
func RenderTreeSVG ¶
RenderTreeSVG converts TreeData into a D2 diagram and renders it as SVG to the given file path.
Types ¶
type FormatType ¶
type FormatType string
FormatType identifies an output format.
const ( // FormatTable renders data as an aligned text table. FormatTable FormatType = "table" // FormatJSON renders data as JSON. FormatJSON FormatType = "json" // FormatYAML renders data as YAML. FormatYAML FormatType = "yaml" )
type Formatter ¶
type Formatter interface {
// Format writes the formatted representation of data to w.
Format(w io.Writer, data any) error
}
Formatter formats data for output.
type JSONFormatter ¶
type JSONFormatter struct {
Pretty bool
}
JSONFormatter formats data as JSON. When Pretty is true, the output is indented for human readability; otherwise it is compact for piping.
type LogHandler ¶
type LogHandler struct {
// contains filtered or unexported fields
}
LogHandler is a custom slog.Handler that produces compact, colored log output with timestamps, aligned level names, and level-based coloring.
23:41:21 DEBUG controller: sending bytes=42 to=192.168.1.100:5540 23:41:21 WARN controller: receive error err=timeout
func NewLogHandler ¶
func NewLogHandler(w io.Writer, level slog.Leveler) *LogHandler
NewLogHandler returns a handler that writes colored, compact log lines to w.
type Stepper ¶
type Stepper struct {
// contains filtered or unexported fields
}
Stepper manages step-by-step progress output with optional spinner animation.
Three modes based on context:
- Verbose: delegates all output to slog so steps and debug logs share one format.
- Interactive (TTY, non-verbose): animated spinner for in-progress, green dot on completion.
- Piped (non-TTY, non-verbose): static lines with dots to stdout.
When silent is true (NewProgressStepper), completed steps leave no permanent trace: in animate mode the spinner line is overwritten in-place; in static mode nothing is printed at all.
Every completed step and terminal call (Success/Fail) appends its elapsed duration as muted text, e.g. "● Establishing PASE session 1.2s".
func NewProgressStepper ¶
NewProgressStepper is like NewStepper but uses silent mode: completed steps leave no permanent trace. In animate (TTY) mode the spinner overwrites a single line continuously. In static (pipe) mode nothing is printed at all.
func NewStepper ¶
NewStepper creates a Stepper that writes to w. When verbose is true, all output is routed through slog for a unified log format. Otherwise, the stepper uses a spinner animation on TTY or static dots when piped.
func (*Stepper) Clear ¶
func (s *Stepper) Clear()
Clear stops the current step (marking it successful) without printing an additional status line. Use this before rendering output so the spinner is cleanly stopped and the terminal cursor is left on a fresh line.
func (*Stepper) Fail ¶
Fail marks the current step as failed and prints an error message with the total elapsed time since the first Step() call (or since this call if no prior step was ever started).
type TableFormatter ¶
type TableFormatter struct{}
TableFormatter formats TableData as a styled text table using lipgloss.
type TreeAttribute ¶
type TreeAttribute struct {
ID uint32
Name string // resolved display name, or "0x%04X" fallback
Value string // empty unless level >= 4
Err string // non-empty if read failed (e.g. "<timeout>")
}
TreeAttribute holds a single attribute entry in the device tree.
type TreeCluster ¶
type TreeCluster struct {
ID uint32
Name string
Side string // "server" or "client"
ListErr string // non-empty if AttributeList read failed
Attrs []TreeAttribute // populated for level >= 3
}
TreeCluster holds a cluster entry with optional attribute data.
type TreeData ¶
type TreeData struct {
NodeID uint64
NodeName string
VendorID uint16
ProductID uint16
SpecificationVersion uint32
SoftwareVersion uint32
SerialNumber string
LastAddress string
Endpoints []TreeEndpoint
Level int
}
TreeData is the full device tree data passed to FormatRichTree.
type TreeEndpoint ¶
type TreeEndpoint struct {
ID uint16
DeviceTypes []store.DeviceType
Clusters []TreeCluster
}
TreeEndpoint holds an endpoint entry with cluster data.