ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
const (
	CheckMark = "✓"
	CrossMark = "✗"
	Arrow     = "→"
	Bang      = "!"
)

Symbols used consistently across every command's output.

Variables

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

func Bold(s string) string

func Cyan

func Cyan(s string) string

func Dim

func Dim(s string) string

func Fail

func Fail(format string, args ...any)

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 Gray

func Gray(s string) string

func Green

func Green(s string) string

func HumanBytes

func HumanBytes(n int64) string

HumanBytes formats n as a human-readable size (B/KB/MB/GB/TB).

func IsTerminal added in v0.2.0

func IsTerminal(f *os.File) bool

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

func Ok(format string, args ...any)

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

func ReadSecret(prompt string) (string, error)

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 Red

func Red(s string) string

func RenderBar

func RenderBar(label string, downloaded, total int64, rate float64) string

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

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

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.

func Warn added in v0.2.0

func Warn(format string, args ...any)

Warn prints a yellow line to stderr for something that succeeded but deserves attention -- distinct from Fail, which means the command did not do what was asked.

func Yellow

func Yellow(s string) string

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

func (p *Progress) Done(id string)

Done removes id's bar -- the download finished or failed, and whatever outcome line the installer logs (via Println) will report it.

func (*Progress) Println

func (p *Progress) Println(s string)

Println prints s above the active bars, keeping them pinned at the bottom.

func (*Progress) Update

func (p *Progress) Update(id, line string)

Update sets (or creates, on first call for id) the bar text for id and redraws.

Jump to

Keyboard shortcuts

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