style

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package style provides styled terminal output using Lipgloss. Output builds lines with Success/Info/Warn/Error and prints as a box. When stderr or stdout is a tty, boxed output wraps only if content is wider than the terminal; otherwise the box stays as narrow as the content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentModeIndicatorLine added in v0.0.7

func AgentModeIndicatorLine(configMode, liveMode string, liveReachable bool, skipUnreachableNote bool) string

AgentModeIndicatorLine shows live backend when the socket is reachable; otherwise config with a note. Secondary details use normal text colour so they stay readable (not faint dim). If skipUnreachableNote is true (e.g. sshush start before the socket exists), omit "(agent not reachable)".

func Box

func Box(s string) string

func BoxWithMaxWidth added in v0.0.7

func BoxWithMaxWidth(s string, maxWidth int) string

BoxWithMaxWidth renders content in a box with word wrapping when lines would exceed the limit: min(terminal width, maxWidth) on a tty when maxWidth > 0, otherwise terminal width; without a tty, maxWidth when maxWidth > 0. When content fits, the box stays as narrow as the content (no full-width padding).

func Dim added in v0.0.7

func Dim(s string) string

func Err

func Err(s string) string

func Focus added in v0.0.5

func Focus(s string) string

func HexWithBackground added in v0.0.6

func HexWithBackground(hex string) string

HexWithBackground renders the hex string (e.g. " #RRGGBB ") with that colour as the terminal background and a contrasting foreground. Returns plain hex if invalid.

func Highlight added in v0.0.5

func Highlight(s string) string

func InputCursorColor added in v0.0.7

func InputCursorColor() color.Color

InputCursorColor returns the theme focus color for the text input cursor (e.g. Cursor.Color).

func SetTheme added in v0.0.5

func SetTheme(t theme.Theme)

SetTheme sets the theme used by all style functions and Output. Call after loading config (e.g. in root PersistentPreRunE).

func StylesForInput added in v0.0.7

func StylesForInput() (boxStyle, focusStyle, blurredStyle lipgloss.Style)

StylesForInput returns the box, focus, and blurred lipgloss styles for use by input components (e.g. passphrase prompt). Use focusStyle for focused state, blurredStyle for unfocused (e.g. placeholder/secondary text).

func Success added in v0.0.5

func Success(s string) string

Standalone style functions - all driven by the current theme (SetTheme).

func TerminalColumns added in v0.0.7

func TerminalColumns() int

TerminalColumns returns the width in columns of the tty attached to stderr, or if stderr is not a tty, stdout. Returns 0 if neither is a terminal or size cannot be read.

func Text added in v0.0.5

func Text(s string) string

func Warn

func Warn(s string) string

Types

type Output

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

Output is a builder for styled terminal output. Append lines with semantic level methods (Success/Info/Warn/Error), then flush with Print() or AsError().

func NewOutput

func NewOutput() *Output

NewOutput returns a new empty Output builder.

func (*Output) Add

func (o *Output) Add(s string) *Output

Add appends a pre-styled string (use for diff symbols or composed lines).

func (*Output) AsError

func (o *Output) AsError() error

AsError wraps the Output in a StyledError for display at the Execute level. Use instead of errors.New() for all user-facing command errors.

func (*Output) Box

func (o *Output) Box() string

Box renders all lines inside a rounded border box string. On a tty, lines wider than the terminal wrap inside the box; otherwise the box is only as wide as the content.

func (*Output) Error

func (o *Output) Error(s string) *Output

func (*Output) Info

func (o *Output) Info(s string) *Output

func (*Output) InfoBold added in v0.0.7

func (o *Output) InfoBold(s string) *Output

func (*Output) Len

func (o *Output) Len() int

Len returns the number of lines added.

func (*Output) Print

func (o *Output) Print()

Print renders as a box to stdout.

func (*Output) PrintErr

func (o *Output) PrintErr()

PrintErr renders as a box to stderr.

func (*Output) PrintTo

func (o *Output) PrintTo(w io.Writer)

PrintTo renders as a box to w.

func (*Output) Spacer

func (o *Output) Spacer() *Output

Spacer appends a blank line for visual separation.

func (*Output) String

func (o *Output) String() string

String renders all lines joined by newlines, without a border.

func (*Output) Success

func (o *Output) Success(s string) *Output

Semantic append methods - encode color from theme, callers describe intent.

func (*Output) Warn

func (o *Output) Warn(s string) *Output

type StyledError

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

StyledError carries a pre-styled Output to be printed by Execute. It prevents cobra from printing a plain "Error: ..." line.

func (*StyledError) Error

func (e *StyledError) Error() string

Error implements the error interface.

func (*StyledError) PrintErr

func (e *StyledError) PrintErr()

PrintErr prints the styled output to stderr.

Jump to

Keyboard shortcuts

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