output

package
v2.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 17 Imported by: 0

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

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 Fatalf

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

Fatalf writes a formatted fatal message and terminates the process with exit code 1.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration returns a human-readable duration string.

func FormatSize

func FormatSize(bytes int64) string

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 LogDebugf

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

LogDebugf writes a formatted debug diagnostic message to the log stream.

func LogInfo

func LogInfo(args ...any)

LogInfo writes an informational diagnostic message to the log stream.

func LogInfof

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

LogInfof writes a formatted informational diagnostic message to the log stream.

func WrapText

func WrapText(text string, width int) string

WrapText wraps text to fit within the given column width, preserving existing newlines and splitting only on whitespace boundaries.

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

func NewConfigured(colorMode string, quiet bool) *Printer

NewConfigured creates a Printer and applies color/quiet configuration.

func NewWithWriter

func NewWithWriter(w io.Writer) *Printer

NewWithWriter creates a Printer that writes to the given writer.

func (*Printer) Blank

func (p *Printer) Blank()

Blank prints an empty line.

func (*Printer) Configure

func (p *Printer) Configure(colorMode string, quiet bool)

Configure applies the given options to the Printer.

func (*Printer) Confirm

func (p *Printer) Confirm(prompt string, defaultYes bool) bool

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) Error

func (p *Printer) Error(a ...any)

Error prints an error-styled message.

func (*Printer) Fatal

func (p *Printer) Fatal(a ...any)

Fatal prints an error-styled message and terminates the process with exit code 1.

func (*Printer) Fatalf

func (p *Printer) Fatalf(format string, a ...any)

Fatalf prints a formatted error-styled message and terminates the process with exit code 1.

func (*Printer) FieldItem

func (p *Printer) FieldItem(key string, value any) string

FieldItem creates a "Key: Value" string for use inside Group() calls.

func (p *Printer) FileLink(absProjectPath, relFilePath, displayName string, line int64) string

FileLink returns a clickable file:// hyperlink for a file path and line.

func (*Printer) GroupItem

func (p *Printer) GroupItem(name string, children ...any) *tree.Tree

GroupItem creates a named sub-tree with children and returns it for use as a nested child inside Group() or Child() calls.

func (p *Printer) Hyperlink(text, url string) string

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

func (p *Printer) IsDebugVerbosity() bool

IsDebugVerbosity returns true for debug-like verbosity modes.

func (*Printer) IsInteractive

func (p *Printer) IsInteractive() bool

IsInteractive returns true if the output is a TTY.

func (*Printer) IsInteractiveUI

func (p *Printer) IsInteractiveUI() bool

IsInteractiveUI returns true when interactive UI components (spinners/progress bars) should be rendered.

func (*Printer) Item

func (p *Printer) Item(value any) string

Item wraps a value as a plain tree child. Useful inside Group() calls.

func (*Printer) Print

func (p *Printer) Print(a ...any)

Print writes a styled string followed by a newline.

func (*Printer) Printf

func (p *Printer) Printf(format string, a ...any)

Printf writes a formatted string followed by a newline.

func (*Printer) RunWithSpinner

func (p *Printer) RunWithSpinner(phase string, run func() error) error

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

func (p *Printer) SetLogWriter(w io.Writer)

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

func (p *Printer) SetVerbosity(level string)

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

func (p *Printer) StyledFieldItem(key string, value any, valueStyle lipgloss.Style) string

StyledFieldItem creates a "Key: Value" string with custom value style.

func (*Printer) Successf

func (p *Printer) Successf(format string, a ...any)

Successf prints a formatted success message.

func (*Printer) Suggest

func (p *Printer) Suggest(description string, command string)

Suggest prints a suggestion section with a description and optional command.

func (*Printer) Theme

func (p *Printer) Theme() *Theme

Theme returns the active theme.

func (*Printer) Warn

func (p *Printer) Warn(a ...any)

Warn prints a warning-styled message.

func (*Printer) Warnf

func (p *Printer) Warnf(format string, a ...any)

Warnf prints a formatted warning message.

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).

Jump to

Keyboard shortcuts

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