terminal

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 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 terminal provides styled CLI output with TTY-aware ANSI colors, progress indicators, and spinners. Ported from the Java CLI's Terminal class.

Index

Constants

View Source
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 Error

func Error(message string)

Error prints a red "error:" prefix to stderr.

func FormatBytes

func FormatBytes(b uint64) string

FormatBytes formats a byte count into a human-readable string (e.g., "1.2 MB").

func FormatDuration

func FormatDuration(d time.Duration) string

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

func FormatNumber(n int64) string

FormatNumber formats an integer with comma separators (e.g., 1500 → "1,500").

func FormatTime

func FormatTime(s string) string

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 Info

func Info(message string)

Info prints a dim/faint message.

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 KeyValueW

func KeyValueW(label, value string, width int)

KeyValueW prints an indented key-value pair with a custom label width.

func List

func List(items []string)

List prints a numbered list of items.

func ProgressBar

func ProgressBar(label string, current, total uint64)

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 ReadLine

func ReadLine(prompt string) string

ReadLine prints a prompt and reads a line of input from stdin.

func Section

func Section(title string)

Section prints a bold section header: \n:: Title\n

func Success

func Success(message string)

Success prints a green checkmark followed by the message.

func Table

func Table(headers []string, rows [][]string)

Table prints an auto-aligned table with dim headers.

func Title

func Title(title string)

Title prints a titled header: \n# Title\n

func ToString

func ToString(color string, parts ...string) string

ToString wraps text with the given ANSI color code. This function does NOT respect TTY detection — it always applies the color. Used by the log handler which manages its own output destination.

func Warn

func Warn(message string)

Warn prints a yellow "warning:" prefix.

Types

type Spinner

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

Spinner displays an animated braille spinner with a message.

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates and starts a new spinner. In non-TTY mode it prints the message once.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop halts the spinner animation and clears the line.

Jump to

Keyboard shortcuts

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