pretty

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package pretty provides consistent, professional CLI output formatting using lipgloss.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accent

func Accent(s string) string

Accent colors text in muted cyan.

func AlignCenter

func AlignCenter(s string, width int) string

AlignCenter centers string within width.

func AlignLeft

func AlignLeft(s string, width int) string

AlignLeft pads string to width with spaces on the right.

func AlignRight

func AlignRight(s string, width int) string

AlignRight pads string to width with spaces on the left.

func Bold

func Bold(s string) string

Bold makes text bold.

func Box

func Box(content string, title string) string

Box draws a simple box around text with optional title.

func Dim

func Dim(s string) string

Dim colors text in gray.

func Error

func Error(s string) string

Error colors text in muted red.

func GetTerminalHeight

func GetTerminalHeight() int

GetTerminalHeight returns the height of the terminal.

func GetTerminalWidth

func GetTerminalWidth() int

GetTerminalWidth returns the width of the terminal.

func Indent

func Indent(s string, spaces int) string

Indent adds leading spaces to each line.

func Info

func Info(s string) string

Info colors text in muted blue.

func IsInteractive

func IsInteractive() bool

IsInteractive returns true if the output is an interactive terminal.

func ShouldUseColor

func ShouldUseColor() bool

ShouldUseColor determines if color output should be enabled.

func Success

func Success(s string) string

Success colors text in muted green.

func Truncate

func Truncate(s string, maxLen int) string

Truncate shortens text to maxLen, adding ellipsis if needed.

func Underline

func Underline(s string) string

Underline underlines text.

func Warning

func Warning(s string) string

Warning colors text in muted gold.

func WrapText

func WrapText(s string, width int) string

WrapText wraps text to specified width.

Types

type ListConfig

type ListConfig struct {
	// ColorEnabled controls whether to use colors in output.
	ColorEnabled bool
	// Indent is the number of spaces per indentation level.
	Indent int
}

ListConfig holds configuration for list rendering.

func DefaultListConfig

func DefaultListConfig() ListConfig

DefaultListConfig returns sensible defaults for list rendering.

type ListStyle

type ListStyle int

ListStyle defines the visual style for lists.

const (
	// StyleBullet uses simple bullet points.
	StyleBullet ListStyle = iota
	// StyleTree uses tree structure with branches.
	StyleTree
	// StyleNumbered uses numbered items.
	StyleNumbered
)

type ListWriter

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

ListWriter provides list rendering with lipgloss styling.

func NewListWriter

func NewListWriter(style ListStyle, config ListConfig) *ListWriter

NewListWriter creates a new list writer with the given style and config.

func (*ListWriter) AppendItem

func (w *ListWriter) AppendItem(item interface{})

AppendItem adds an item to the list.

func (*ListWriter) AppendItems

func (w *ListWriter) AppendItems(items []interface{})

AppendItems adds multiple items to the list.

func (*ListWriter) Indent

func (w *ListWriter) Indent()

Indent increases the indentation level for subsequent items.

func (*ListWriter) Render

func (w *ListWriter) Render(out io.Writer)

Render outputs the list to the given writer.

func (*ListWriter) RenderString

func (w *ListWriter) RenderString() string

RenderString returns the list as a string.

func (*ListWriter) UnIndent

func (w *ListWriter) UnIndent()

UnIndent decreases the indentation level.

type Pager

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

Pager handles paginated output for long content.

func NewPager

func NewPager(config PagerConfig) *Pager

NewPager creates a new pager with the given configuration.

func (*Pager) Page

func (p *Pager) Page(content string) error

Page displays content with pagination if in an interactive terminal. If not interactive (piped or redirected), content is displayed without pagination. Supports spacebar/Enter for next page, up/down arrows for line scrolling, and 'q' to quit.

func (*Pager) PageLines

func (p *Pager) PageLines(lines []string) error

PageLines is a convenience method for paging a slice of strings.

type PagerConfig

type PagerConfig struct {
	// PageSize is the number of lines per page (0 = auto-detect from terminal height)
	PageSize int
	// Output is where paginated content is written
	Output io.Writer
}

PagerConfig holds configuration for the pager.

func DefaultPagerConfig

func DefaultPagerConfig() PagerConfig

DefaultPagerConfig returns sensible defaults for pagination.

type ProgressConfig

type ProgressConfig struct {
	// Enabled controls whether progress is shown
	Enabled bool
	// Output is where progress is written (usually os.Stderr)
	Output io.Writer
	// UpdateFrequency controls how often progress updates
	UpdateFrequency time.Duration
}

ProgressConfig holds configuration for progress tracking.

func DefaultProgressConfig

func DefaultProgressConfig() ProgressConfig

DefaultProgressConfig returns sensible defaults for progress tracking.

type ProgressTracker

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

ProgressTracker manages multiple progress indicators using lipgloss.

func NewProgressTracker

func NewProgressTracker(config ProgressConfig) *ProgressTracker

NewProgressTracker creates a new progress tracker.

func (*ProgressTracker) Increment

func (pt *ProgressTracker) Increment(id string)

Increment increments the progress for a specific tracker.

func (*ProgressTracker) IsActive

func (pt *ProgressTracker) IsActive() bool

IsActive returns whether the tracker is currently active.

func (*ProgressTracker) MarkDone

func (pt *ProgressTracker) MarkDone(id string)

MarkDone marks a tracker as complete.

func (*ProgressTracker) MarkError

func (pt *ProgressTracker) MarkError(id string)

MarkError marks a tracker as failed.

func (*ProgressTracker) Start

func (pt *ProgressTracker) Start()

Start starts rendering progress.

func (*ProgressTracker) Stop

func (pt *ProgressTracker) Stop()

Stop stops rendering progress.

func (*ProgressTracker) Track

func (pt *ProgressTracker) Track(id, message string, total int64)

Track adds a new progress tracker with the given ID and message.

func (*ProgressTracker) Update

func (pt *ProgressTracker) Update(id string, current int64)

Update updates the progress for a specific tracker.

func (*ProgressTracker) UpdateMessage

func (pt *ProgressTracker) UpdateMessage(id, message string)

UpdateMessage updates the message for a specific tracker.

type TableConfig

type TableConfig struct {
	// MaxWidth is the maximum table width (0 = auto-detect from terminal).
	MaxWidth int
	// ColorEnabled controls whether to use colors in output.
	ColorEnabled bool
	// AutoWrap enables automatic text wrapping in columns.
	AutoWrap bool
	// SortColumn is the column index to sort by (-1 = no sorting).
	SortColumn int
	// SortAsc controls sort direction (true = ascending).
	SortAsc bool
}

TableConfig holds configuration for table rendering.

func DefaultTableConfig

func DefaultTableConfig() TableConfig

DefaultTableConfig returns sensible defaults for table rendering.

type TableStyle

type TableStyle int

TableStyle defines the visual style for tables.

const (
	// StyleBordered uses rounded borders with full table structure.
	StyleBordered TableStyle = iota
	// StyleLight uses light borders for a clean look.
	StyleLight
	// StyleMinimal uses no borders, just spacing (default).
	StyleMinimal
	// StyleCompact uses dense formatting for large datasets.
	StyleCompact
)

type TableWriter

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

TableWriter provides table rendering with lipgloss styling.

func NewTableWriter

func NewTableWriter(style TableStyle, config TableConfig) *TableWriter

NewTableWriter creates a new table writer with the given style and config.

func (*TableWriter) AppendRow

func (w *TableWriter) AppendRow(row ...interface{})

AppendRow adds a data row to the table.

func (*TableWriter) AppendRows

func (w *TableWriter) AppendRows(rows [][]interface{})

AppendRows adds multiple data rows.

func (*TableWriter) AppendSeparator

func (w *TableWriter) AppendSeparator()

AppendSeparator adds a visual separator line (no-op for lipgloss implementation).

func (*TableWriter) Render

func (w *TableWriter) Render(out io.Writer)

Render outputs the table to the given writer.

func (*TableWriter) RenderString

func (w *TableWriter) RenderString() string

RenderString returns the rendered table as a string.

func (*TableWriter) SetAutoIndex

func (w *TableWriter) SetAutoIndex(enabled bool)

SetAutoIndex enables row numbering (no-op for lipgloss implementation).

func (*TableWriter) SetColumnConfig

func (w *TableWriter) SetColumnConfig(columnNumber int, config interface{})

SetColumnConfig sets configuration for a specific column (no-op for lipgloss implementation).

func (*TableWriter) SetHeader

func (w *TableWriter) SetHeader(headers ...interface{})

SetHeader sets the table header row.

func (*TableWriter) SortBy

func (w *TableWriter) SortBy(columnNumber int, ascending bool)

SortBy sorts the table by the configured column (no-op for lipgloss implementation).

Jump to

Keyboard shortcuts

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