Documentation
¶
Overview ¶
Package terminal provides styled CLI output with TTY-aware ANSI colors, progress indicators, and spinners. Ported from the Java CLI's Terminal class.
Index ¶
- Constants
- func Error(message string)
- func FormatBytes(b uint64) string
- func FormatDuration(d time.Duration) string
- func FormatNumber(n int64) string
- func FormatTime(s string) string
- func Info(message string)
- func IsTTY() bool
- func KeyValue(label, value string)
- func KeyValueW(label, value string, width int)
- func List(items []string)
- func ProgressBar(label string, current, total uint64)
- func ReadLine(prompt string) string
- func Section(title string)
- func Success(message string)
- func Table(headers []string, rows [][]string)
- func Title(title string)
- func ToString(color string, parts ...string) string
- func Warn(message string)
- type Spinner
Constants ¶
const ( Reset = "\033[0m" Bold = "\033[1m" Dim = "\033[2m" Default = "\033[39m" Black = "\033[30m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" White = "\033[37m" BrightBlack = "\033[90m" BrightRed = "\033[91m" BrightGreen = "\033[92m" BrightYellow = "\033[93m" BrightBlue = "\033[94m" BrightMagenta = "\033[95m" BrightCyan = "\033[96m" BrightWhite = "\033[97m" )
ANSI color and style constants
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes formats a byte count into a human-readable string (e.g., "1.2 MB").
func FormatDuration ¶
FormatDuration formats a duration for human display with at most 1 decimal place. Examples: "245 ms", "2.5 s", "1.2 min", "3 h", "2 d"
func FormatNumber ¶
FormatNumber formats an integer with comma separators (e.g., 1500 → "1,500").
func FormatTime ¶
FormatTime parses an ISO8601/RFC3339 time string and returns it formatted in RFC1123 in the local timezone. If parsing fails, the original string is returned.
func IsTTY ¶
func IsTTY() bool
IsTTY returns true if stdout is a terminal and color output is not suppressed.
func KeyValue ¶
func KeyValue(label, value string)
KeyValue prints an indented key-value pair with the default label width (15).
func ProgressBar ¶
ProgressBar displays a progress bar. In TTY mode it overwrites the current line. In non-TTY mode it only prints the final line when current == total. Silently returns when total <= 0.
func Success ¶
func Success(message string)
Success prints a green checkmark followed by the message.
Types ¶
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner displays an animated braille spinner with a message.
func NewSpinner ¶
NewSpinner creates and starts a new spinner. In non-TTY mode it prints the message once.