output

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package output provides output formatting for Sigil CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanRenderQR

func CanRenderQR(w io.Writer) bool

CanRenderQR checks if the output writer is a terminal suitable for QR rendering.

func FormatError

func FormatError(w io.Writer, err error, format Format) error

FormatError formats an error for display.

func FormatSuccess

func FormatSuccess(w io.Writer, message string, format Format) error

FormatSuccess formats a success message.

func Info added in v1.2.0

func Info(msg string)

Info prints an informational message to stdout with an info prefix.

func Infof added in v1.2.0

func Infof(format string, args ...any)

Infof prints a formatted informational message to stdout.

func RenderQR

func RenderQR(w io.Writer, data string, cfg QRConfig) error

RenderQR renders a QR code to the writer if it's a terminal. Returns without error if the writer is not a terminal (no output is produced).

func Success added in v1.2.0

func Success(msg string)

Success prints a success message to stdout with a success prefix.

func Successf added in v1.2.0

func Successf(format string, args ...any)

Successf prints a formatted success message to stdout.

func Warn added in v1.2.0

func Warn(msg string)

Warn prints a warning message to stderr with a warning prefix.

func Warnf added in v1.2.0

func Warnf(format string, args ...any)

Warnf prints a formatted warning message to stderr.

Types

type ErrorDetail

type ErrorDetail struct {
	Code       string            `json:"code"`
	Message    string            `json:"message"`
	Details    map[string]string `json:"details,omitempty"`
	Suggestion string            `json:"suggestion,omitempty"`
	ExitCode   int               `json:"exit_code"`
}

ErrorDetail contains error details.

type ErrorOutput

type ErrorOutput struct {
	Error ErrorDetail `json:"error"`
}

ErrorOutput represents a structured error for JSON output.

type Format

type Format string

Format represents the output format.

const (
	FormatText Format = "text"
	FormatJSON Format = "json"
	FormatAuto Format = "auto"
)

Output format constants.

func DetectFormat

func DetectFormat(w io.Writer, explicit Format) Format

DetectFormat determines the appropriate format based on context. Returns JSON for non-TTY output, text for TTY, unless explicitly overridden.

func ParseFormat

func ParseFormat(s string) Format

ParseFormat parses a format string.

type Formatter

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

Formatter handles output formatting.

func NewFormatter

func NewFormatter(format Format, w io.Writer) *Formatter

NewFormatter creates a new formatter with the specified format.

func (*Formatter) Format

func (f *Formatter) Format() Format

Format returns the current output format.

func (*Formatter) IsJSON

func (f *Formatter) IsJSON() bool

IsJSON returns true if the formatter outputs JSON.

func (*Formatter) Print

func (f *Formatter) Print(v any) error

Print writes formatted output.

func (*Formatter) Printf

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

Printf writes formatted text output.

func (*Formatter) Println

func (f *Formatter) Println(args ...any) error

Println writes a line of text output.

func (*Formatter) Writer

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

Writer returns the output writer.

type QRConfig

type QRConfig struct {
	// Level is the error correction level.
	Level qr.Level
	// QuietZone is the number of empty blocks around the QR code.
	QuietZone int
	// HalfBlocks uses half-height blocks for a more compact display.
	HalfBlocks bool
}

QRConfig configures QR code rendering.

func DefaultQRConfig

func DefaultQRConfig() QRConfig

DefaultQRConfig returns sensible defaults for terminal QR rendering.

type Table

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

Table renders tabular data for text output.

func NewTable

func NewTable(headers ...string) *Table

NewTable creates a new table with the given headers.

func (*Table) AddRow

func (t *Table) AddRow(cells ...string)

AddRow adds a row to the table.

func (*Table) Render

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

Render renders the table to the writer.

func (*Table) SetNoHeader

func (t *Table) SetNoHeader(noHeader bool)

SetNoHeader suppresses the header row.

func (*Table) SetSeparator

func (t *Table) SetSeparator(sep string)

SetSeparator sets the column separator.

func (*Table) String

func (t *Table) String() string

String returns the table as a string.

Jump to

Keyboard shortcuts

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