terminal

package
v0.0.69 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 21 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

View Source
var ActivityRenderWaitTimeout = 2 * time.Second
View Source
var DefaultRuntimeMetricsInterval = time.Second

Functions

func BuildStageCount added in v0.0.68

func BuildStageCount(selection OutputSelection) int

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 ErrorText added in v0.0.62

func ErrorText(value any) string

func FormatActivity added in v0.0.68

func FormatActivity(update printingpress.ActivityUpdate) string

FormatActivity renders a single printing press activity update as plain text.

func FormatCount added in v0.0.68

func FormatCount[T ~int | ~int64](value T) string

func FormatRuntimeMetrics added in v0.0.68

func FormatRuntimeMetrics(snapshot RuntimeMetricsSnapshot) string

func FormatStatusLine added in v0.0.68

func FormatStatusLine(label, message string) string

FormatStatusLine renders a stage/status pair as plain text.

func FprintBox added in v0.0.62

func FprintBox(writer io.Writer, content string, opts BoxOptions)

FprintBox writes a rendered box to writer, defaulting to stdout.

func FprintBulletList added in v0.0.62

func FprintBulletList(writer io.Writer, items []BulletListItem)

FprintBulletList writes a rendered bullet list to writer, defaulting to stdout.

func HumanBytes added in v0.0.68

func HumanBytes(size int64) string

HumanBytes formats a byte count using binary units.

func HumanRuntimeBytes added in v0.0.68

func HumanRuntimeBytes(size uint64) string

func LogSuccess added in v0.0.62

func LogSuccess(logger *slog.Logger, msg string, args ...any)

LogSuccess writes a success-style log record using the PrettyHandler success level.

func MutedText added in v0.0.62

func MutedText(value any) string

func NewCLIPrettyLogger added in v0.0.62

func NewCLIPrettyLogger(writer io.Writer, level slog.Leveler) *slog.Logger

NewCLIPrettyLogger creates a PrettyHandler-backed logger for CLI output.

func NewPrettyLogger added in v0.0.50

func NewPrettyLogger(opts *PrettyHandlerOptions) *slog.Logger

NewPrettyLogger creates a new slog.Logger with a PrettyHandler.

func PrimaryText added in v0.0.62

func PrimaryText(value any) string

func PrintAggregateSummary added in v0.0.68

func PrintAggregateSummary(writer io.Writer, palette Palette, catalog *ppmodel.CatalogSite, htmlStats, jsonStats, llmStats *printingpress.AggregatePressStatistics, totalDuration time.Duration, fileCount int, totalBytes int64)

func PrintBanner added in v0.0.50

func PrintBanner(opts BannerOptions)

PrintBanner renders the shared pb33f banner for a CLI product.

func PrintSummary added in v0.0.68

func PrintSummary(writer io.Writer, palette Palette, site *ppmodel.Site, htmlStats, llmStats *printingpress.PressStatistics, totalDuration time.Duration, fileCount int, totalBytes int64)

func RenderBox added in v0.0.62

func RenderBox(content string, opts BoxOptions) string

RenderBox renders content inside a deterministic Unicode box.

func RenderBulletList added in v0.0.62

func RenderBulletList(items []BulletListItem) string

RenderBulletList renders a nested bullet list.

func RenderPanelGrid added in v0.0.62

func RenderPanelGrid(rows [][]string, opts PanelOptions) string

RenderPanelGrid renders a rectangular grid of pre-rendered panel strings.

func RoundDuration added in v0.0.68

func RoundDuration(d time.Duration) time.Duration

RoundDuration trims terminal-facing durations to millisecond precision.

func RunWithActivity added in v0.0.68

func RunWithActivity[T any](pp *printingpress.PrintingPress, renderer ActivityRenderer, run func() (T, error)) (T, error)

RunWithActivity renders a printing press activity stream while run executes.

func ScanOutputDir added in v0.0.68

func ScanOutputDir(root string) (int, int64, error)

ScanOutputDir returns the count and combined size of files below root.

func SecondaryText added in v0.0.62

func SecondaryText(value any) string

func SuccessText added in v0.0.62

func SuccessText(value any) string

func WarningText added in v0.0.62

func WarningText(value any) string

Types

type ActivityRenderMode added in v0.0.68

type ActivityRenderMode int

ActivityRenderMode controls how printing press activity is presented.

const (
	ActivityRenderModePlain ActivityRenderMode = iota
	ActivityRenderModeProgress
	ActivityRenderModeDebug
)

func SelectActivityRenderMode added in v0.0.68

func SelectActivityRenderMode(writer io.Writer, debug bool) ActivityRenderMode

type ActivityRenderer added in v0.0.68

type ActivityRenderer interface {
	RenderActivity(sub *printingpress.ActivitySubscription)
	UpdateManual(stage, task, status string, percent float64, elapsed time.Duration, err error)
	Close()
}

ActivityRenderer renders single-spec printing press progress.

func NewActivityRenderer added in v0.0.68

func NewActivityRenderer(mode ActivityRenderMode, writer io.Writer, palette Palette, totalStages int, logger *slog.Logger) ActivityRenderer

type AggregatePoolRenderer added in v0.0.68

type AggregatePoolRenderer interface {
	Report(update printingpress.AggregateProgressUpdate)
	ReportRuntimeMetrics(snapshot RuntimeMetricsSnapshot)
	Close()
}

AggregatePoolRenderer renders aggregate printing press pool progress.

func NewAggregatePoolRenderer added in v0.0.68

func NewAggregatePoolRenderer(mode ActivityRenderMode, writer io.Writer, palette Palette, logger *slog.Logger) AggregatePoolRenderer

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 BoxOptions added in v0.0.62

type BoxOptions struct {
	Title         string
	PaddingLeft   int
	PaddingRight  int
	PaddingTop    int
	PaddingBottom int
}

BoxOptions configures a simple terminal box renderer.

type BuildLoggerSession added in v0.0.68

type BuildLoggerSession struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

BuildLoggerSession routes slog output so it does not fight live progress.

func ConfigureBuildLogger added in v0.0.68

func ConfigureBuildLogger(writer io.Writer, palette Palette, mode ActivityRenderMode) *BuildLoggerSession

func (*BuildLoggerSession) Finish added in v0.0.68

func (s *BuildLoggerSession) Finish(runErr error)

type BulletListItem added in v0.0.62

type BulletListItem struct {
	Level int
	Text  string
}

BulletListItem describes one item in a nested bullet list.

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 OutputSelection added in v0.0.68

type OutputSelection struct {
	HTML        bool
	LLM         bool
	JSON        bool
	Diagnostics bool
}

OutputSelection describes which output stages a build will run.

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 PaletteForPrintingPressArgs added in v0.0.68

func PaletteForPrintingPressArgs(args []string) 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 PanelOptions added in v0.0.62

type PanelOptions struct {
	Gap int
}

PanelOptions configures panel grid rendering.

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 RuntimeMetricsMonitor added in v0.0.68

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

func StartRuntimeMetricsMonitor added in v0.0.68

func StartRuntimeMetricsMonitor(start time.Time, interval time.Duration, report func(RuntimeMetricsSnapshot)) *RuntimeMetricsMonitor

func (*RuntimeMetricsMonitor) Close added in v0.0.68

func (m *RuntimeMetricsMonitor) Close()

type RuntimeMetricsSnapshot added in v0.0.68

type RuntimeMetricsSnapshot struct {
	Elapsed    time.Duration
	HeapAlloc  uint64
	TotalAlloc uint64
	Sys        uint64
	NumGC      uint32
	Goroutines int
}

func CaptureRuntimeMetrics added in v0.0.68

func CaptureRuntimeMetrics(start time.Time) RuntimeMetricsSnapshot

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 TextStyler added in v0.0.62

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

TextStyler applies semantic terminal styles derived from a Palette.

func DefaultTextStyler added in v0.0.62

func DefaultTextStyler() TextStyler

DefaultTextStyler returns styles for the default dark terminal theme.

func NewTextStyler added in v0.0.62

func NewTextStyler(p Palette) TextStyler

NewTextStyler creates semantic text styles for a terminal palette.

func (TextStyler) Error added in v0.0.62

func (t TextStyler) Error(value any) string

func (TextStyler) Muted added in v0.0.62

func (t TextStyler) Muted(value any) string

func (TextStyler) Primary added in v0.0.62

func (t TextStyler) Primary(value any) string

func (TextStyler) Secondary added in v0.0.62

func (t TextStyler) Secondary(value any) string

func (TextStyler) Success added in v0.0.62

func (t TextStyler) Success(value any) string

func (TextStyler) Warning added in v0.0.62

func (t TextStyler) Warning(value any) 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

func ParsePrintingPressTheme added in v0.0.68

func ParsePrintingPressTheme(raw string) (ThemeName, error)

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