format

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package format provides pluggable CLI output renderers for backlogit commands. Callers select a renderer by Format value and write structured row data via the Renderer interface. All renderers write to an io.Writer and return an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	// Key is the map key used to look up the value from a row.
	Key string
	// Header is the column heading shown in table and tile output.
	Header string
}

Column describes a single output column.

type Format

type Format string

Format specifies the output format selected by the --format flag.

const (
	// FormatTable renders output as a tab-separated table with a header row.
	FormatTable Format = "table"
	// FormatJSON renders output as a compact JSON array where each element
	// contains only the columns requested.
	FormatJSON Format = "json"
	// FormatTile renders output as blank-line-separated property-value blocks.
	FormatTile Format = "tile"
)

type JSONRenderer

type JSONRenderer struct{}

JSONRenderer renders rows as a JSON array. Each element contains only the keys present in the supplied columns slice.

func NewJSONRenderer

func NewJSONRenderer() *JSONRenderer

NewJSONRenderer returns a ready-to-use JSONRenderer.

func (*JSONRenderer) Render

func (j *JSONRenderer) Render(w io.Writer, columns []Column, rows []map[string]any) error

Render writes rows as a JSON array to w. Each array element is an object whose keys are the Column.Key values in the supplied columns slice. An empty rows slice produces "[]".

type Renderer

type Renderer interface {
	Render(w io.Writer, columns []Column, rows []map[string]any) error
}

Renderer writes structured row data to an io.Writer in a specific format.

type TableRenderer

type TableRenderer struct{}

TableRenderer renders rows as a tab-separated table using tabwriter. The first row is a header containing column headings.

func NewTableRenderer

func NewTableRenderer() *TableRenderer

NewTableRenderer returns a ready-to-use TableRenderer.

func (*TableRenderer) Render

func (t *TableRenderer) Render(w io.Writer, columns []Column, rows []map[string]any) error

Render writes a header row followed by data rows to w using tabwriter padding. Column order follows the columns slice. Each row occupies exactly one output line.

type TileRenderer

type TileRenderer struct {
	Bold bool
}

TileRenderer renders rows as blank-line-separated property-value blocks. Each block contains one "Header: value" line per column. Bold controls whether ANSI bold escape sequences are applied to the first property line of each block. Callers set Bold based on TTY detection; the renderer does not auto-detect terminal capabilities.

func NewTileRenderer

func NewTileRenderer(bold bool) *TileRenderer

NewTileRenderer returns a TileRenderer with the given bold setting.

func (*TileRenderer) Render

func (t *TileRenderer) Render(w io.Writer, columns []Column, rows []map[string]any) error

Render writes each row as a block of "Header: value" lines, separated by blank lines between blocks (but not after the final block). When Bold is true the first property line of each block is wrapped in ANSI bold escape sequences.

Jump to

Keyboard shortcuts

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