ui

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 11 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 ui is the shared terminal-UX layer: colour and TTY detection, status output, and the check table.

The primary caller of this binary is a GitHub Actions runner, not a person: the packs' scheduled workflows run it every Monday. So non-interactive behaviour is the default case rather than a degraded one -- no prompts unless stdin is a terminal, no ANSI into a log file, and a non-zero exit whenever something failed.

Index

Constants

This section is empty.

Variables

View Source
var (
	GlyphsUnicode = Glyphs{
		Check: "✓", Cross: "✗", Warn: "⚠", Info: "ℹ",
		Active: "◉", Pending: "○", Paused: "⏸",
		Retrying: "↻", Skipped: "⊘",
		Cursor: "▸", Bullet: "•",
		Dash: "—", Ellipsis: "…",
		Arrow: "→", Branch: "├─", Corner: "└─",
		BarFull: "█", BarEmpty: "░",
	}
	GlyphsASCII = Glyphs{
		Check: "[OK]", Cross: "[X]", Warn: "[!]", Info: "[i]",
		Active: "[..]", Pending: "[ ]", Paused: "[P]",
		Retrying: "[R]", Skipped: "[-]",
		Cursor: ">", Bullet: "*",
		Dash: "-", Ellipsis: "...",
		Arrow: "->", Branch: "|-", Corner: "`-",
		BarFull: "#", BarEmpty: ".",
	}
)

GlyphsUnicode and GlyphsASCII are exported so a golden test can pin one and produce identical output regardless of the host.

View Source
var Sym = pickGlyphs()

Sym is the active glyph set.

Functions

func ASCII

func ASCII() bool

ASCII reports whether to fall back to ASCII glyphs.

IMT_ASCII forces the fallback and IMT_UNICODE forces Unicode; otherwise only a legacy Windows console gets ASCII. The overrides exist because the detection below is a heuristic and a user on an unusual terminal should not have to argue with it.

When both are set, ASCII wins. That is the safe direction: someone who set IMT_ASCII most likely has a terminal that renders Unicode as mojibake, and honouring the other variable there produces unreadable output, whereas the reverse merely produces plainer output than necessary.

func AssumeYes

func AssumeYes() bool

AssumeYes reports whether confirmations are pre-answered.

func Bold

func Bold(s string) string

Bold, Dim, OK, Warn and Err style a string for the active profile.

func Dim

func Dim(s string) string

func Err

func Err(s string) string

func Failure

func Failure(format string, a ...any)

func Heading

func Heading(s string)

Heading writes a section heading.

func Info

func Info(format string, a ...any)

func Init

func Init(c Config)

Init configures the layer. Call once from the root command before any subcommand runs.

func Interactive

func Interactive() bool

Interactive reports whether prompting is allowed.

func JSON

func JSON(v any) error

JSON writes a value as indented JSON to stdout.

func JSONMode

func JSONMode() bool

JSONMode reports whether output should be machine-readable.

func OK

func OK(s string) string

func Printf

func Printf(format string, a ...any)

Printf writes to stdout unless quiet.

func Println

func Println(a ...any)

Println writes a line to stdout unless quiet.

func RenderCheckTable

func RenderCheckTable(rows []CheckRow) string

RenderCheckTable renders the check results.

It lives here rather than in either front-end so the CLI and the TUI show the same five columns in the same order; drift between them would be invisible until someone compared two screenshots.

func SetGlyphs

func SetGlyphs(g Glyphs)

SetGlyphs pins a set, for golden tests.

func Status

func Status(glyph, format string, a ...any)

Status writes a status line to stderr.

Status, progress and diagnostics go to stderr so stdout carries only the command's actual output -- which is what makes `icon-sets-sync check --json | jq` work.

func Success

func Success(format string, a ...any)

Success, Failure, Warning and Info are the four status shapes.

func Summarise

func Summarise(results []checker.Result)

Summarise writes the one-line verdict under the check table.

It reports unresolved packs separately from stale ones. Counting only stale packs means a run in which every registry was unreachable prints "All packs up to date" -- nothing was known to be behind, because nothing was looked at. That is the false green the Python reporter shipped.

func Table

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

Table renders rows under headers, padded to the widest cell per column.

Deliberately plain: no box drawing. This output is read as often in a CI log as in a terminal, and a bordered table is noise there.

func Warn

func Warn(s string) string

func Warning

func Warning(format string, a ...any)

Types

type CheckRow

type CheckRow struct {
	Package, Current, Latest, Status, Detail string
}

CheckRow is one row of the upstream-check table, front-end agnostic.

func CheckRows

func CheckRows(results []checker.Result) []CheckRow

CheckRows maps results to display rows, colouring the status per verdict.

Both front-ends call this rather than mapping independently: a status glyph that differed between the CLI and the TUI would be invisible until someone compared two screenshots.

type Config

type Config struct {
	AssumeYes bool
	NoInput   bool
	NoColor   bool
	JSON      bool
	Quiet     bool
	Out       io.Writer
	Err       io.Writer
}

Config carries the resolved global flags.

type Glyphs

type Glyphs struct {
	Check, Cross, Warn, Info string
	Active, Pending, Paused  string
	Retrying, Skipped        string
	Cursor, Bullet           string
	Dash, Ellipsis           string
	Arrow, Branch, Corner    string
	BarFull, BarEmpty        string
}

Glyphs is the display symbol set, chosen once for the running terminal.

Legacy Windows consoles (bare cmd.exe, old conhost) have no Unicode font and render box-drawing and status glyphs as "?" or empty boxes. Everywhere else -- macOS, Linux, WSL, Windows Terminal, VS Code -- gets the Unicode set.

The status vocabulary is the terminal handbook's: one symbol per bucket, so a reader learns the mental model once. The ASCII column is its documented fallback set.

Jump to

Keyboard shortcuts

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