output

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SeverityColor

func SeverityColor(severity, text string) string

SeverityColor returns a colored string based on severity level.

Types

type Format

type Format string

Format represents an output format.

const (
	FormatText     Format = "text"
	FormatJSON     Format = "json"
	FormatMarkdown Format = "markdown"
	FormatTOON     Format = "toon"
)

func ParseFormat

func ParseFormat(s string) Format

ParseFormat converts a string to Format, defaulting to text.

type Formatter

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

Formatter handles output formatting.

func NewFormatter

func NewFormatter(format Format, output string, colored bool) (*Formatter, error)

NewFormatter creates a new formatter.

func (*Formatter) Close

func (f *Formatter) Close() error

Close closes the formatter's writer if it's a file.

func (*Formatter) Colored

func (f *Formatter) Colored() bool

Colored returns whether colored output is enabled.

func (*Formatter) Error

func (f *Formatter) Error(format string, args ...any)

func (*Formatter) Format

func (f *Formatter) Format() Format

Format returns the configured format.

func (*Formatter) Info

func (f *Formatter) Info(format string, args ...any)

func (*Formatter) Output

func (f *Formatter) Output(data any) error

Output writes data in the configured format.

func (*Formatter) Success

func (f *Formatter) Success(format string, args ...any)

func (*Formatter) Warning

func (f *Formatter) Warning(format string, args ...any)

func (*Formatter) Writer

func (f *Formatter) Writer() io.Writer

Writer returns the underlying writer.

type Renderable

type Renderable interface {
	RenderText(w io.Writer, colored bool) error
	RenderMarkdown(w io.Writer) error
	// RenderData returns the underlying data for JSON/TOON serialization.
	RenderData() any
}

Renderable defines data that can render itself in multiple formats.

type Report

type Report struct {
	Title    string       `json:"title,omitempty" toon:"title"`
	Sections []Renderable `json:"-" toon:"-"`
	Data     any          `json:"data,omitempty" toon:"data"`
}

Report is a compound Renderable containing multiple sections and tables.

func (*Report) RenderData

func (r *Report) RenderData() any

func (*Report) RenderMarkdown

func (r *Report) RenderMarkdown(w io.Writer) error

func (*Report) RenderText

func (r *Report) RenderText(w io.Writer, colored bool) error

type Section

type Section struct {
	Title    string    `json:"title,omitempty" toon:"title"`
	Content  string    `json:"content,omitempty" toon:"content"`
	Sections []Section `json:"sections,omitempty" toon:"sections"`
	Data     any       `json:"data,omitempty" toon:"data"`
}

Section is a Renderable titled section with content and subsections.

func (*Section) RenderData

func (s *Section) RenderData() any

func (*Section) RenderMarkdown

func (s *Section) RenderMarkdown(w io.Writer) error

func (*Section) RenderText

func (s *Section) RenderText(w io.Writer, colored bool) error

type Table

type Table struct {
	Title   string     `json:"-" toon:"-"`
	Headers []string   `json:"-" toon:"-"`
	Rows    [][]string `json:"-" toon:"-"`
	Footer  []string   `json:"-" toon:"-"`
	Data    any        `json:"data,omitempty" toon:"data"`
}

Table is a Renderable table with headers, rows, and optional footer.

func NewTable

func NewTable(title string, headers []string, rows [][]string, footer []string, data any) *Table

NewTable creates a table that wraps structured data for serialization.

func (*Table) RenderData

func (t *Table) RenderData() any

func (*Table) RenderMarkdown

func (t *Table) RenderMarkdown(w io.Writer) error

func (*Table) RenderText

func (t *Table) RenderText(w io.Writer, colored bool) error

type TextSection

type TextSection = Section

type TextTable

type TextTable = Table

Jump to

Keyboard shortcuts

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