terminal

package
v0.0.59 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// reset clears all formatting
	Reset = "\033[0m"

	// green is used for additions (ANSI 256-color code 46)
	Green = "\033[38;5;46m"

	// yellow is used for modifications (ANSI 256-color code 220)
	Yellow = "\033[38;5;220m"

	// red is used for removals (ANSI 256-color code 196)
	Red = "\033[38;5;196m"

	// redBold is used for breaking changes - bold red for emphasis
	RedBold = "\033[1;38;5;196m"

	// grey is used for tree structure and location info (ANSI 256-color code 240)
	Grey = "\033[38;5;240m"
)

ANSI escape codes retained for compatibility with existing terminal renderers.

View Source
const (
	LipglossGreen     = "46"
	LipglossYellow    = "220"
	LipglossRed       = "196"
	LipglossGrey      = "240"
	LipglossLightGrey = "246"

	// pb33f dark-theme brand colors from cowboy-components.
	LipglossPrimaryBlue   = "#62c4ff"
	LipglossSecondaryPink = "#f83aff"
)

Legacy lipgloss-compatible color constants retained for compatibility.

View Source
const (
	TimeFormatFull     = time.RFC3339
	TimeFormatDateTime = "2006-01-02 15:04:05"
	TimeFormatTimeOnly = "15:04:05"
)

TimeFormat constants for common timestamp formats.

View Source
const LevelSuccess = slog.Level(2) // between Info (0) and Warn (4)

LevelSuccess is a custom log level for success messages.

Variables

This section is empty.

Functions

func DetectDarkBackground added in v0.0.50

func DetectDarkBackground() bool

func DetectDarkBackgroundFromEnv added in v0.0.55

func DetectDarkBackgroundFromEnv(env []string) bool

func DetectProfile added in v0.0.50

func DetectProfile(output io.Writer, env []string) colorprofile.Profile

func DetectStdoutProfile added in v0.0.50

func DetectStdoutProfile() colorprofile.Profile

func NewPrettyLogger added in v0.0.50

func NewPrettyLogger(opts *PrettyHandlerOptions) *slog.Logger

NewPrettyLogger creates a new slog.Logger with a PrettyHandler.

func PrintBanner added in v0.0.50

func PrintBanner(opts BannerOptions)

PrintBanner renders the shared pb33f banner for a CLI product.

Types

type BannerOptions added in v0.0.50

type BannerOptions struct {
	Writer      io.Writer
	Palette     Palette
	ProductName string
	ProductURL  string
	Version     string
	Date        string
}

BannerOptions describes the product metadata to print alongside the shared pb33f banner art.

type ColorScheme

type ColorScheme interface {
	Addition(text string) string
	Modification(text string) string
	Removal(text string) string
	Breaking(text string) string
	TreeBranch(text string) string
	LocationInfo(text string) string
	Statistics(text string) string
	Detail(text string) string
}

ColorScheme defines how to colorize different elements of tree output. implementations can provide terminal colors, grayscale dimming, or no colors.

func NewThemeColorScheme added in v0.0.50

func NewThemeColorScheme(theme ThemeName, profile colorprofile.Profile, darkBackground bool) ColorScheme

type GrayscaleColorScheme

type GrayscaleColorScheme struct{}

GrayscaleColorScheme retains backwards-compatible grayscale output.

func (GrayscaleColorScheme) Addition

func (GrayscaleColorScheme) Addition(s string) string

func (GrayscaleColorScheme) Breaking

func (GrayscaleColorScheme) Breaking(s string) string

func (GrayscaleColorScheme) Detail added in v0.0.50

func (GrayscaleColorScheme) LocationInfo

func (GrayscaleColorScheme) LocationInfo(s string) string

func (GrayscaleColorScheme) Modification

func (GrayscaleColorScheme) Modification(s string) string

func (GrayscaleColorScheme) Removal

func (GrayscaleColorScheme) Removal(s string) string

func (GrayscaleColorScheme) Statistics

func (GrayscaleColorScheme) Statistics(s string) string

func (GrayscaleColorScheme) TreeBranch

func (GrayscaleColorScheme) TreeBranch(s string) string

type NoColorScheme

type NoColorScheme struct{}

func (NoColorScheme) Addition

func (NoColorScheme) Addition(s string) string

func (NoColorScheme) Breaking

func (NoColorScheme) Breaking(s string) string

func (NoColorScheme) Detail added in v0.0.50

func (NoColorScheme) Detail(s string) string

func (NoColorScheme) LocationInfo

func (NoColorScheme) LocationInfo(s string) string

func (NoColorScheme) Modification

func (NoColorScheme) Modification(s string) string

func (NoColorScheme) Removal

func (NoColorScheme) Removal(s string) string

func (NoColorScheme) Statistics

func (NoColorScheme) Statistics(s string) string

func (NoColorScheme) TreeBranch

func (NoColorScheme) TreeBranch(s string) string

type Palette added in v0.0.50

type Palette struct {
	Theme          ThemeName
	Profile        colorprofile.Profile
	DarkBackground bool
	SupportsColor  bool

	Primary        color.Color
	Secondary      color.Color
	Addition       color.Color
	Modification   color.Color
	Removal        color.Color
	Breaking       color.Color
	Muted          color.Color
	Detail         color.Color
	Nav            color.Color
	HelpKey        color.Color
	PrimaryBG      color.Color
	SecondaryBG    color.Color
	SubtleBG       color.Color
	SelectedBG     color.Color
	RangeBG        color.Color
	AddedBG        color.Color
	AddedRangeBG   color.Color
	RemovedBG      color.Color
	RemovedRangeBG color.Color
}

func PaletteFor added in v0.0.50

func PaletteFor(theme ThemeName, output io.Writer, env []string, darkBackground bool) Palette

func PaletteForProfile added in v0.0.50

func PaletteForProfile(theme ThemeName, profile colorprofile.Profile, darkBackground bool) Palette

func PaletteForTheme added in v0.0.50

func PaletteForTheme(theme ThemeName) Palette

type PrettyHandler added in v0.0.50

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

PrettyHandler is a slog.Handler that outputs logs in a tree format with colors derived from the terminal Palette.

func NewPrettyHandler added in v0.0.50

func NewPrettyHandler(opts *PrettyHandlerOptions) *PrettyHandler

NewPrettyHandler creates a new PrettyHandler with the given options.

func (*PrettyHandler) Buffered added in v0.0.50

func (h *PrettyHandler) Buffered() string

Buffered returns the currently buffered pretty log output.

func (*PrettyHandler) Enabled added in v0.0.50

func (h *PrettyHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*PrettyHandler) Flush added in v0.0.50

func (h *PrettyHandler) Flush() error

Flush writes any buffered pretty log output to the configured writer.

func (*PrettyHandler) Handle added in v0.0.50

func (h *PrettyHandler) Handle(_ context.Context, r slog.Record) error

Handle handles the Record.

func (*PrettyHandler) Reset added in v0.0.50

func (h *PrettyHandler) Reset()

Reset clears any buffered pretty log output.

func (*PrettyHandler) WithAttrs added in v0.0.50

func (h *PrettyHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new Handler with the given attributes added. The returned handler shares the parent's mutex to ensure thread-safe writes to the same underlying Writer.

func (*PrettyHandler) WithGroup added in v0.0.50

func (h *PrettyHandler) WithGroup(name string) slog.Handler

WithGroup returns a new Handler with the given group appended to the receiver's existing groups.

type PrettyHandlerOptions added in v0.0.50

type PrettyHandlerOptions struct {
	// Level is the minimum level to log. Defaults to slog.LevelInfo.
	Level slog.Leveler

	// TimeFormat is the format for timestamps. Defaults to TimeFormatFull (RFC3339).
	TimeFormat string

	// Writer is the output destination. Defaults to os.Stdout.
	Writer io.Writer

	// Palette provides colors for styling. Defaults to PaletteForTheme(ThemeDark).
	Palette *Palette

	// Buffer defers writes until Flush is called.
	Buffer bool
}

PrettyHandlerOptions configures the PrettyHandler.

type TerminalColorScheme

type TerminalColorScheme struct{}

TerminalColorScheme retains backwards-compatible full semantic ANSI output.

func (TerminalColorScheme) Addition

func (TerminalColorScheme) Addition(s string) string

func (TerminalColorScheme) Breaking

func (TerminalColorScheme) Breaking(s string) string

func (TerminalColorScheme) Detail added in v0.0.50

func (TerminalColorScheme) Detail(s string) string

func (TerminalColorScheme) LocationInfo

func (TerminalColorScheme) LocationInfo(s string) string

func (TerminalColorScheme) Modification

func (TerminalColorScheme) Modification(s string) string

func (TerminalColorScheme) Removal

func (TerminalColorScheme) Removal(s string) string

func (TerminalColorScheme) Statistics

func (TerminalColorScheme) Statistics(s string) string

func (TerminalColorScheme) TreeBranch

func (TerminalColorScheme) TreeBranch(s string) string

type ThemeName added in v0.0.50

type ThemeName string
const (
	ThemeDark      ThemeName = "dark"
	ThemeLight     ThemeName = "light"
	ThemeTektronix ThemeName = "tektronix"
)

func NormalizeThemeName added in v0.0.50

func NormalizeThemeName(theme ThemeName) ThemeName

type ThemedColorScheme added in v0.0.50

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

func (ThemedColorScheme) Addition added in v0.0.50

func (t ThemedColorScheme) Addition(s string) string

func (ThemedColorScheme) Breaking added in v0.0.50

func (t ThemedColorScheme) Breaking(s string) string

func (ThemedColorScheme) Detail added in v0.0.50

func (t ThemedColorScheme) Detail(s string) string

func (ThemedColorScheme) LocationInfo added in v0.0.50

func (t ThemedColorScheme) LocationInfo(s string) string

func (ThemedColorScheme) Modification added in v0.0.50

func (t ThemedColorScheme) Modification(s string) string

func (ThemedColorScheme) Removal added in v0.0.50

func (t ThemedColorScheme) Removal(s string) string

func (ThemedColorScheme) Statistics added in v0.0.50

func (t ThemedColorScheme) Statistics(s string) string

func (ThemedColorScheme) TreeBranch added in v0.0.50

func (t ThemedColorScheme) TreeBranch(s string) string

Jump to

Keyboard shortcuts

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