Documentation
¶
Overview ¶
Package output provides a DSL-like API for producing styled CLI output. It uses lipgloss for styling, glamour for markdown rendering, and bubbles for interactive components like spinners and progress bars.
Index ¶
- func Fatal(args ...any)
- func Fatalf(format string, args ...any)
- func FormatDuration(d time.Duration) string
- func FormatSize(bytes int64) string
- func LogDebug(args ...any)
- func LogDebugf(format string, args ...any)
- func LogInfo(args ...any)
- func LogInfof(format string, args ...any)
- func WrapText(text string, width int) string
- type DebugStreamWriter
- type Printer
- func (p *Printer) Blank()
- func (p *Printer) Configure(colorMode string, quiet bool)
- func (p *Printer) Confirm(prompt string, defaultYes bool) bool
- func (p *Printer) CopyWithProgress(dst io.Writer, src io.Reader, total int64, label string) (int64, error)
- func (p *Printer) DebugStream(label string) *DebugStreamWriter
- func (p *Printer) Error(a ...any)
- func (p *Printer) Fatal(a ...any)
- func (p *Printer) Fatalf(format string, a ...any)
- func (p *Printer) FieldItem(key string, value any) string
- func (p *Printer) FileLink(absProjectPath, relFilePath, displayName string, line int64) string
- func (p *Printer) GroupItem(name string, children ...any) *tree.Tree
- func (p *Printer) Hyperlink(text, url string) string
- func (p *Printer) InteractiveBlank()
- func (p *Printer) IsDebugVerbosity() bool
- func (p *Printer) IsInteractive() bool
- func (p *Printer) IsInteractiveUI() bool
- func (p *Printer) Item(value any) string
- func (p *Printer) Print(a ...any)
- func (p *Printer) Printf(format string, a ...any)
- func (p *Printer) RunWithSpinner(phase string, run func() error) error
- func (p *Printer) Section(title string) *SectionBuilder
- func (p *Printer) SetLogWriter(w io.Writer)
- func (p *Printer) SetVerbosity(level string)
- func (p *Printer) Snippet() *SnippetBuilder
- func (p *Printer) StartSpinner(message string) *SpinnerHandle
- func (p *Printer) StyledFieldItem(key string, value any, valueStyle lipgloss.Style) string
- func (p *Printer) Successf(format string, a ...any)
- func (p *Printer) Suggest(description string, command string)
- func (p *Printer) Theme() *Theme
- func (p *Printer) Warn(a ...any)
- func (p *Printer) Warnf(format string, a ...any)
- type SectionBuilder
- func (sb *SectionBuilder) Child(children ...any) *SectionBuilder
- func (sb *SectionBuilder) Field(key string, value any) *SectionBuilder
- func (sb *SectionBuilder) Group(name string, children ...any) *SectionBuilder
- func (sb *SectionBuilder) Line() *SectionBuilder
- func (sb *SectionBuilder) Render()
- func (sb *SectionBuilder) String() string
- func (sb *SectionBuilder) StyledField(key string, value any, valueStyle lipgloss.Style) *SectionBuilder
- func (sb *SectionBuilder) StyledText(text string, style lipgloss.Style) *SectionBuilder
- func (sb *SectionBuilder) Text(text string) *SectionBuilder
- func (sb *SectionBuilder) WithStyle(s lipgloss.Style) *SectionBuilder
- type SnippetBuilder
- type SpinnerHandle
- type Theme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
func Fatal(args ...any)
Fatal writes a fatal message and terminates the process with exit code 1.
func FormatDuration ¶
FormatDuration returns a human-readable duration string.
func FormatSize ¶
FormatSize returns a human-readable byte size string.
func LogDebug ¶
func LogDebug(args ...any)
LogDebug writes a debug diagnostic message to the log stream.
func LogInfo ¶
func LogInfo(args ...any)
LogInfo writes an informational diagnostic message to the log stream.
Types ¶
type DebugStreamWriter ¶
type DebugStreamWriter struct {
// contains filtered or unexported fields
}
DebugStreamWriter writes labeled and indented debug output to stderr. The source label is printed once before the first line.
func (*DebugStreamWriter) WriteLine ¶
func (d *DebugStreamWriter) WriteLine(text string)
WriteLine prints one line of debug output with source grouping.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer is the central output abstraction. All user-facing output goes through a Printer instance. It holds the active theme, the output writer, and knows whether it's writing to a TTY.
func New ¶
func New() *Printer
New creates a Printer that writes to os.Stdout with the default theme. Color support is auto-detected based on the terminal.
func NewConfigured ¶
NewConfigured creates a Printer and applies color/quiet configuration.
func NewWithWriter ¶
NewWithWriter creates a Printer that writes to the given writer.
func (*Printer) Confirm ¶
Confirm shows a Y/N prompt and returns true if the user accepts. If not interactive, returns the default value.
func (*Printer) CopyWithProgress ¶
func (p *Printer) CopyWithProgress(dst io.Writer, src io.Reader, total int64, label string) (int64, error)
CopyWithProgress copies src to dst while displaying a progress bar on interactive terminals. Falls back to plain io.Copy otherwise.
func (*Printer) DebugStream ¶
func (p *Printer) DebugStream(label string) *DebugStreamWriter
DebugStream creates a writer for streaming debug output for a source.
func (*Printer) Fatal ¶
Fatal prints an error-styled message and terminates the process with exit code 1.
func (*Printer) Fatalf ¶
Fatalf prints a formatted error-styled message and terminates the process with exit code 1.
func (*Printer) GroupItem ¶
GroupItem creates a named sub-tree with children and returns it for use as a nested child inside Group() or Child() calls.
func (*Printer) Hyperlink ¶
Hyperlink returns an OSC 8 terminal hyperlink if the terminal supports it, otherwise returns plain text.
func (*Printer) InteractiveBlank ¶ added in v2.6.3
func (p *Printer) InteractiveBlank()
InteractiveBlank prints an empty line only when interactive UI components are enabled.
func (*Printer) IsDebugVerbosity ¶
IsDebugVerbosity returns true for debug-like verbosity modes.
func (*Printer) IsInteractive ¶
IsInteractive returns true if the output is a TTY.
func (*Printer) IsInteractiveUI ¶
IsInteractiveUI returns true when interactive UI components (spinners/progress bars) should be rendered.
func (*Printer) RunWithSpinner ¶
RunWithSpinner wraps a function with a spinner animation. If the terminal is non-interactive, the function runs without visual feedback.
func (*Printer) Section ¶
func (p *Printer) Section(title string) *SectionBuilder
Section starts building a new titled output section.
func (*Printer) SetLogWriter ¶
SetLogWriter configures an additional writer for plain-text output mirroring. Mirrored output has ANSI escapes stripped and is useful for writing user-facing section output to log files.
func (*Printer) SetVerbosity ¶
SetVerbosity stores the configured log verbosity to control interactive UI elements like spinners and progress bars.
func (*Printer) Snippet ¶
func (p *Printer) Snippet() *SnippetBuilder
Snippet starts building a code snippet renderer.
func (*Printer) StartSpinner ¶
func (p *Printer) StartSpinner(message string) *SpinnerHandle
StartSpinner creates and starts a new spinner. Call Stop() or StopError() on the returned handle when the operation completes.
func (*Printer) StyledFieldItem ¶
StyledFieldItem creates a "Key: Value" string with custom value style.
type SectionBuilder ¶
type SectionBuilder struct {
// contains filtered or unexported fields
}
SectionBuilder builds and renders a titled tree section.
func (*SectionBuilder) Child ¶
func (sb *SectionBuilder) Child(children ...any) *SectionBuilder
Child adds any tree node directly (string, *tree.Tree, etc).
func (*SectionBuilder) Field ¶
func (sb *SectionBuilder) Field(key string, value any) *SectionBuilder
Field adds a "Key: Value" node to the section.
func (*SectionBuilder) Group ¶
func (sb *SectionBuilder) Group(name string, children ...any) *SectionBuilder
Group adds a named sub-tree with children.
func (*SectionBuilder) Line ¶
func (sb *SectionBuilder) Line() *SectionBuilder
Line adds a blank line separator.
func (*SectionBuilder) Render ¶
func (sb *SectionBuilder) Render()
Render builds and prints the section.
func (*SectionBuilder) String ¶
func (sb *SectionBuilder) String() string
String returns the rendered section as a string without printing.
func (*SectionBuilder) StyledField ¶
func (sb *SectionBuilder) StyledField(key string, value any, valueStyle lipgloss.Style) *SectionBuilder
StyledField adds a "Key: Value" node with a custom style for the value.
func (*SectionBuilder) StyledText ¶
func (sb *SectionBuilder) StyledText(text string, style lipgloss.Style) *SectionBuilder
StyledText adds a text node rendered with a given style.
func (*SectionBuilder) Text ¶
func (sb *SectionBuilder) Text(text string) *SectionBuilder
Text adds a plain text node.
func (*SectionBuilder) WithStyle ¶
func (sb *SectionBuilder) WithStyle(s lipgloss.Style) *SectionBuilder
WithStyle sets a lipgloss style for the section title.
type SnippetBuilder ¶
type SnippetBuilder struct {
// contains filtered or unexported fields
}
SnippetBuilder provides a fluent interface for loading and formatting code snippets around a target line.
func (*SnippetBuilder) LoadLinesOrEmpty ¶
func (sb *SnippetBuilder) LoadLinesOrEmpty(filePath string, centerLine int64) []string
LoadLinesOrEmpty loads a snippet and returns it as tree-friendly lines. centerLine is 1-based.
func (*SnippetBuilder) LoadOrEmpty ¶
func (sb *SnippetBuilder) LoadOrEmpty(filePath string, centerLine int64) string
LoadOrEmpty loads a snippet, returning empty string on any error. centerLine is 1-based.
type SpinnerHandle ¶
type SpinnerHandle struct {
// contains filtered or unexported fields
}
SpinnerHandle controls a running spinner.
func (*SpinnerHandle) Stop ¶
func (h *SpinnerHandle) Stop(finalMessage string)
Stop completes the spinner with a success indicator.
func (*SpinnerHandle) StopError ¶
func (h *SpinnerHandle) StopError(finalMessage string)
StopError completes the spinner with an error indicator.
type Theme ¶
type Theme struct {
// Semantic styles for severity levels
Error lipgloss.Style
Warning lipgloss.Style
Note lipgloss.Style
Success lipgloss.Style
Info lipgloss.Style
Debug lipgloss.Style
Muted lipgloss.Style
// Component styles
HeaderTitle lipgloss.Style
HeaderBorder lipgloss.Style
TreeBranch lipgloss.Style
TreeItem lipgloss.Style
FieldKey lipgloss.Style
FieldValue lipgloss.Style
Suggestion lipgloss.Style
Command lipgloss.Style
FilePath lipgloss.Style
// Spinner symbols
SpinnerDone string
SpinnerFail string
SpinnerStyle lipgloss.Style
DoneStyle lipgloss.Style
FailStyle lipgloss.Style
// Snippet styles
SnippetBorder lipgloss.Style
SnippetLine lipgloss.Style
SnippetHighlight lipgloss.Style
SnippetLineNum lipgloss.Style
}
Theme holds all the visual styles used throughout the CLI. Changing a theme field changes the appearance everywhere it's referenced.
func DefaultTheme ¶
func DefaultTheme(_ colorprofile.Profile) *Theme
DefaultTheme returns the default seqra theme adapted for light/dark terminals. Colors are specified with ANSI 16 indexes so output follows the active terminal theme.
func PlainTheme ¶
func PlainTheme() *Theme
PlainTheme returns a theme with no colors or styles (for non-TTY / --color=never).