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 ¶
- func AgentModeIndicatorLine(configMode, liveMode string, liveReachable bool, skipUnreachableNote bool) string
- func Box(s string) string
- func BoxWithMaxWidth(s string, maxWidth int) string
- func Dim(s string) string
- func Err(s string) string
- func Focus(s string) string
- func HexWithBackground(hex string) string
- func Highlight(s string) string
- func InputCursorColor() color.Color
- func SetTheme(t theme.Theme)
- func StylesForInput() (boxStyle, focusStyle, blurredStyle lipgloss.Style)
- func Success(s string) string
- func TerminalColumns() int
- func Text(s string) string
- func Warn(s string) string
- type Output
- func (o *Output) Add(s string) *Output
- func (o *Output) AsError() error
- func (o *Output) Box() string
- func (o *Output) Error(s string) *Output
- func (o *Output) Info(s string) *Output
- func (o *Output) InfoBold(s string) *Output
- func (o *Output) Len() int
- func (o *Output) Print()
- func (o *Output) PrintErr()
- func (o *Output) PrintTo(w io.Writer)
- func (o *Output) Spacer() *Output
- func (o *Output) String() string
- func (o *Output) Success(s string) *Output
- func (o *Output) Warn(s string) *Output
- type StyledError
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 BoxWithMaxWidth ¶ added in v0.0.7
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 HexWithBackground ¶ added in v0.0.6
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 InputCursorColor ¶ added in v0.0.7
InputCursorColor returns the theme focus color for the text input cursor (e.g. Cursor.Color).
func SetTheme ¶ added in v0.0.5
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
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
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.
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 (*Output) AsError ¶
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 ¶
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.
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.