Documentation
¶
Overview ¶
Package termui provides terminal-safe styling for croc's command-line output.
Index ¶
- Constants
- func Color(text, style string, enabled bool) string
- func Emphasis(text string, enabled bool) string
- func Error(text string, enabled bool) string
- func Filename(text string, enabled bool) string
- func FitProgressDescription(description string) string
- func LoggerOutput(file *os.File) io.Writer
- func NewProgress(config ProgressConfig) *progressbar.ProgressBar
- func Output(file *os.File) (io.Writer, bool)
- func Plain(text string) string
- func ProgressDescription(action, filename string, colorEnabled bool) string
- func PromptChoices(prompt string, enabled bool) string
- func Secret(text string, enabled bool) string
- func Success(text string, enabled bool) string
- func Warning(text string, enabled bool) string
- type ProgressConfig
Constants ¶
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 Emphasis ¶
Emphasis highlights routine labels and choices without assigning a status color to them.
func Filename ¶
Filename highlights a path like Git highlights file metadata: bold, using the terminal's own foreground color.
func FitProgressDescription ¶
FitProgressDescription reserves room for the progress bar's variable metadata and truncates the description by terminal display width.
func LoggerOutput ¶
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 Plain ¶
Plain removes terminal styling from text. It is useful when measuring or comparing strings that may contain ANSI sequences.
func ProgressDescription ¶
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 ¶
PromptChoices leaves conventional yes/no choices unstyled.
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.