Documentation
¶
Overview ¶
Package ui provides goop's terminal styling: colors, symbols, and aligned tables. No external dependency -- ANSI escape codes are simple enough to emit directly, and the one genuinely Windows-specific piece (a console won't interpret them without opting in) is a small, well-defined syscall.
Index ¶
- Constants
- Variables
- func Bold(s string) string
- func Cyan(s string) string
- func Dim(s string) string
- func Fail(format string, args ...any)
- func Gray(s string) string
- func Green(s string) string
- func HumanBytes(n int64) string
- func IsTerminal(f *os.File) bool
- func Ok(format string, args ...any)
- func ReadSecret(prompt string) (string, error)
- func Red(s string) string
- func RenderBar(label string, downloaded, total int64, rate float64) string
- func Table(header []string, rows [][]string) string
- func Warn(format string, args ...any)
- func Yellow(s string) string
- type Progress
Constants ¶
const ( CheckMark = "✓" CrossMark = "✗" Arrow = "→" Bang = "!" )
Symbols used consistently across every command's output.
Variables ¶
var Enabled = detectColor()
Enabled reports whether color output is active. False when NO_COLOR is set, when GOOP_NO_COLOR is set, or when either stdout or stderr isn't a real console (redirected to a file or pipe) -- goop writes interleaved output to both, so both need to be real consoles for color to make sense.
Functions ¶
func Fail ¶
Fail prints a red cross-mark line to stderr. Every command's error path goes through this, so failures look consistent regardless of which command produced them.
func HumanBytes ¶
HumanBytes formats n as a human-readable size (B/KB/MB/GB/TB).
func IsTerminal ¶ added in v0.2.0
IsTerminal reports whether f is a real console rather than a redirected file or pipe. Unlike enableVirtualTerminal it only asks and changes nothing, so it is safe on stdin -- used to decide whether a destructive command may prompt at all. A command that cannot prompt must refuse rather than assume consent.
func Ok ¶
Ok prints a green checkmark line to stdout, for a command's own successful, one-shot outcome (not per-app install progress, which goes through the Logf-driven line styling instead).
func ReadSecret ¶ added in v0.2.0
ReadSecret asks for a secret without echoing it, the way sudo does.
A secret passed as a command-line argument leaks twice over: into the shell's history file, and into the process list where any other process on the machine can read it while the command runs. Neither is recoverable after the fact, which is why goop asks instead.
When stdin is not a console -- a pipe, a here-string, CI -- the line is read plainly, so `echo $TOKEN | goop auth add ...` still works. There is nothing to hide from in that case: the value never reaches a terminal, and the caller has already decided how to protect it.
func RenderBar ¶
RenderBar formats one progress line: a filled/empty block bar, percent, human-readable byte counts, and transfer rate. total <= 0 means the size is unknown (no Content-Length header) -- shown as a running byte count with no bar/percentage rather than a fake one.
func Table ¶
Table renders header + rows as aligned columns with a bold header and a dim separator rule. Cells may already contain ANSI color codes; width is computed from visible characters regardless.
Types ¶
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress renders one live, in-place line per active download (A1: the installer's worker pool runs several at once), redrawn via ANSI cursor movement so bars update without scrolling the terminal. Println shares the same lock and always prints above the bars, erasing and redrawing them around the line so ordinary log output and the bars never tear or overwrite each other.
Falls back to plain scrolling output (no erase/redraw) when Enabled is false -- output redirected, NO_COLOR, etc. -- since cursor-movement tricks only make sense on a real terminal, and Update still logs nothing extra in that case rather than spamming a redirected log with dozens of intermediate frames.
func NewProgress ¶
func NewProgress() *Progress
func (*Progress) Done ¶
Done removes id's bar -- the download finished or failed, and whatever outcome line the installer logs (via Println) will report it.