termui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package termui provides terminal-safe styling for croc's command-line output.

Index

Constants

View Source
const (
	Bold   = "\x1b[1m"
	Red    = "\x1b[31m"
	Green  = "\x1b[32m"
	Yellow = "\x1b[33m"
	Cyan   = "\x1b[36m"
	Reset  = "\x1b[0m"
)

Variables

This section is empty.

Functions

func Color

func Color(text, style string, enabled bool) string

Color applies a semantic terminal style when color is enabled.

func Emphasis

func Emphasis(text string, enabled bool) string

Emphasis highlights routine labels and choices without assigning a status color to them.

func Error

func Error(text string, enabled bool) string

Error highlights fatal errors.

func Filename

func Filename(text string, enabled bool) string

Filename highlights a path like Git highlights file metadata: bold, using the terminal's own foreground color.

func FitProgressDescription

func FitProgressDescription(description string) string

FitProgressDescription reserves room for the progress bar's variable metadata and truncates the description by terminal display width.

func LoggerOutput

func LoggerOutput(file *os.File) io.Writer

LoggerOutput normalizes the logger's Linux-only ANSI prefixes and applies croc's portable warning and error styles.

func NewProgress

func NewProgress(config ProgressConfig) *progressbar.ProgressBar

NewProgress creates either croc's standard determinate progress bar or its matching indeterminate spinner.

func Output

func Output(file *os.File) (io.Writer, bool)

Output returns a Windows-aware writer and whether styling should be used.

func Plain

func Plain(text string) string

Plain removes terminal styling from text. It is useful when measuring or comparing strings that may contain ANSI sequences.

func ProgressDescription

func ProgressDescription(action, filename string, colorEnabled bool) string

ProgressDescription styles only the filename portion and gives it enough room to remain recognizable when the complete progress line is narrowed. The action should include any desired separator, such as "Hashing ".

func PromptChoices

func PromptChoices(prompt string, enabled bool) string

PromptChoices leaves conventional yes/no choices unstyled.

func Secret

func Secret(text string, enabled bool) string

Secret highlights a share code like Git highlights an object identifier.

func Success

func Success(text string, enabled bool) string

Success highlights completed operations.

func Warning

func Warning(text string, enabled bool) string

Warning highlights cautions and recoverable problems.

Types

type ProgressConfig

type ProgressConfig struct {
	Max           int64
	Description   string
	Writer        io.Writer
	ColorEnabled  bool
	Hidden        bool
	ClearOnFinish bool
	Throttle      time.Duration
	OnCompletion  func()
}

ProgressConfig describes a CLI progress indicator using croc's shared terminal presentation. A negative Max creates an indeterminate spinner.

Jump to

Keyboard shortcuts

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