ui

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ui provides terminal output writers with color profile support.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidColor = errors.New("invalid --color value")

ErrInvalidColor is returned when an unsupported --color value is given.

Functions

func RenderTable

func RenderTable(headers []string, rows [][]string, color bool) string

RenderTable builds a formatted table string using lipgloss. When color is true, headers are styled and borders are rendered with color. When color is false, a plain ASCII table is produced.

func WithUI

func WithUI(ctx context.Context, u *UI) context.Context

WithUI stores the UI in the context.

Types

type Options

type Options struct {
	Stdout io.Writer
	Stderr io.Writer
	Color  string // auto, always, never
}

Options configures the UI.

type Printer

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

Printer wraps a termenv.Output with a resolved color profile.

func (*Printer) ColorEnabled

func (p *Printer) ColorEnabled() bool

ColorEnabled returns true when color output is active.

func (*Printer) Errorf

func (p *Printer) Errorf(format string, args ...any)

Errorf writes a formatted error line prefixed with "Error: ".

func (*Printer) Print

func (p *Printer) Print(msg string)

Print writes a string without a trailing newline.

func (*Printer) Printf

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

Printf writes a formatted line to the output.

func (*Printer) Println

func (p *Printer) Println(msg string)

Println writes a line to the output.

func (*Printer) Successf

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

Successf writes a formatted success line with green color.

type UI

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

UI wraps stdout and stderr printers with color profile support.

func FromContext

func FromContext(ctx context.Context) *UI

FromContext retrieves the UI from the context.

func New

func New(opts Options) (*UI, error)

New creates a UI with the given options.

func (*UI) Err

func (u *UI) Err() *Printer

Err returns the stderr printer.

func (*UI) Out

func (u *UI) Out() *Printer

Out returns the stdout printer.

Jump to

Keyboard shortcuts

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