output

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeNotFound         = "not_found"
	ErrCodeAuthFailed       = "auth_failed"
	ErrCodeForbidden        = "forbidden"
	ErrCodeValidationFailed = "validation_failed"
	ErrCodeServerError      = "server_error"
	ErrCodeUnknown          = "unknown"
)

Error codes emitted in JSON error envelopes.

View Source
const (
	ActionCreated     = "created"
	ActionUpdated     = "updated"
	ActionDeleted     = "deleted"
	ActionClosed      = "closed"
	ActionReopened    = "reopened"
	ActionAssigned    = "assigned"
	ActionCommented   = "commented"
	ActionLogged      = "logged"
	ActionUserAdded   = "user_added"
	ActionUserRemoved = "user_removed"
	ActionLoggedIn    = "logged_in"
	ActionLoggedOut   = "logged_out"
	ActionSwitched    = "switched"
	ActionInstalled   = "installed"
	ActionOpened      = "opened"
)

Action actions exposed by no-body mutators. Keep the vocabulary small.

View Source
const (
	FormatTable = "table"
	FormatJSON  = "json"
	FormatCSV   = "csv"
)

Format constants for output modes.

Variables

View Source
var (
	StyleNew        = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
	StyleInProgress = lipgloss.NewStyle().Foreground(lipgloss.Color("11"))
	StyleResolved   = lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
	StyleClosed     = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
	StyleRejected   = lipgloss.NewStyle().Foreground(lipgloss.Color("9"))

	StyleHighPrio   = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true)
	StyleNormalPrio = lipgloss.NewStyle().Foreground(lipgloss.Color("7"))
	StyleLowPrio    = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))

	StyleID      = lipgloss.NewStyle().Foreground(lipgloss.Color("6")).Bold(true)
	StyleHeader  = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("15"))
	StyleLabel   = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
	StyleSuccess = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
	StyleError   = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true)
	StyleWarning = lipgloss.NewStyle().Foreground(lipgloss.Color("11"))
)

Functions

func IsTerminal

func IsTerminal() bool

IsTerminal checks if stdout is a terminal.

func PriorityStyle

func PriorityStyle(name string) lipgloss.Style

PriorityStyle returns the appropriate style for a priority name.

func RenderActionJSON

func RenderActionJSON(w io.Writer, env ActionEnvelope) error

RenderActionJSON writes an action envelope as pretty-printed JSON.

func RenderCSV

func RenderCSV(w io.Writer, headers []string, rows [][]string) error

RenderCSV renders headers and rows as CSV to the writer.

func RenderErrorJSON

func RenderErrorJSON(w io.Writer, env ErrorEnvelope) error

RenderErrorJSON writes an error envelope as pretty-printed JSON.

func RenderJSON

func RenderJSON(w io.Writer, v interface{}) error

RenderJSON renders a value as pretty-printed JSON to the writer.

func RenderTable

func RenderTable(w io.Writer, headers []string, rows [][]string, noColor bool)

RenderTable renders a table with headers and rows to the writer.

func StartSpinner

func StartSpinner(msg string, isTTY bool) func()

StartSpinner starts a spinner with the given message and returns a stop function.

func StatusStyle

func StatusStyle(name string) lipgloss.Style

StatusStyle returns the appropriate style for a status name.

func SupportsWarnings

func SupportsWarnings(format string) bool

SupportsWarnings reports whether human-readable warnings should be emitted for the selected output format.

Types

type ActionEnvelope

type ActionEnvelope struct {
	Ok       bool   `json:"ok"`
	Action   string `json:"action"`
	Resource string `json:"resource"`
	ID       any    `json:"id,omitempty"`
	Message  string `json:"message,omitempty"`
}

ActionEnvelope is the JSON shape emitted by no-body mutators.

type ErrorDetail

type ErrorDetail struct {
	Message string   `json:"message"`
	Code    string   `json:"code,omitempty"`
	Details []string `json:"details,omitempty"`
}

ErrorDetail describes a failed command execution.

type ErrorEnvelope

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

ErrorEnvelope is the JSON shape emitted for command failures in JSON mode.

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

KeyValue is a label-value pair for detail views.

type Printer

type Printer interface {
	Table(headers []string, rows [][]string)
	Detail(pairs []KeyValue)
	JSON(v interface{})
	CSV(headers []string, rows [][]string)
	Success(msg string)
	Error(msg string)
	Warning(msg string)
	// Outcome emits a completed command result. In JSON mode this writes a
	// stable envelope to stdout. In other modes it writes the human message to
	// stderr as either success or warning text.
	Outcome(ok bool, action, resource string, id any, humanMsg string)
	// Resource emits a resource body in JSON mode and a human success message
	// in other formats.
	Resource(v any, humanMsg string)
	// Action emits a completed-mutation result. In JSON mode this writes a
	// compact action envelope to stdout. In any other mode it writes the
	// human message to stderr via Success.
	Action(action, resource string, id any, humanMsg string)
	Spinner(msg string) func()
	Format() string
}

Printer handles all output rendering.

type StdPrinter

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

StdPrinter is the standard implementation of Printer.

func NewStdPrinter

func NewStdPrinter(out, errOut io.Writer, isTTY, noColor bool, format string) *StdPrinter

NewStdPrinter creates a new StdPrinter.

func (*StdPrinter) Action

func (p *StdPrinter) Action(action, resource string, id any, humanMsg string)

func (*StdPrinter) CSV

func (p *StdPrinter) CSV(headers []string, rows [][]string)

func (*StdPrinter) Detail

func (p *StdPrinter) Detail(pairs []KeyValue)

func (*StdPrinter) Error

func (p *StdPrinter) Error(msg string)

func (*StdPrinter) Format

func (p *StdPrinter) Format() string

func (*StdPrinter) JSON

func (p *StdPrinter) JSON(v interface{})

func (*StdPrinter) Outcome

func (p *StdPrinter) Outcome(ok bool, action, resource string, id any, humanMsg string)

func (*StdPrinter) Resource

func (p *StdPrinter) Resource(v any, humanMsg string)

func (*StdPrinter) Spinner

func (p *StdPrinter) Spinner(msg string) func()

func (*StdPrinter) Success

func (p *StdPrinter) Success(msg string)

func (*StdPrinter) Table

func (p *StdPrinter) Table(headers []string, rows [][]string)

func (*StdPrinter) Warning

func (p *StdPrinter) Warning(msg string)

Jump to

Keyboard shortcuts

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