{"modulePath":"github.com/CommitBrief/commitbrief","version":"v1.23.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package ui\n\n## Functions\n\n```go\nfunc AcceptsYes(answer string, catalog *i18n.Catalog) bool\n```\nAcceptsYes reports whether \\`answer\\` is an affirmative response. The EN defaults (\"y\"/\"yes\") are always accepted. When catalog is non-nil, the catalog's \\`common.yes\\_short\\` / \\`common.yes\\_long\\` strings are added to the accepted set (Turkish: \"e\"/\"evet\").\n\n\\`answer\\` is assumed already trimmed and lower-cased by the caller. Catalog values are normalised here so a catalog with mixed case still matches.\n\n```go\nfunc AskYesNo(r io.Reader, w io.Writer, question string, opts AskOptions) (bool, error)\n```\nAskYesNo asks question on w and reads a yes/no response from r. AssumeYes short-circuits to true; NonInteractive (without AssumeYes) short-circuits to false. Default (empty answer) is no.\n\nAccepted-yes vocabulary: case-insensitive, trimmed match against \"y\"/\"yes\" (always) plus the active catalog's \\`common.yes\\_short\\` / \\`common.yes\\_long\\` (Turkish: \"e\"/\"evet\"). See AskOptions.Catalog.\n\n```go\nfunc Clip(s string, max int) string\n```\nClip truncates s to at most max display columns (rune count, a good enough proxy here), appending \"…\" when it cuts. max \\\u003c= 0 means \"no limit\", matching TerminalWidth's \"0 = unknown\" convention.\n\nKeeping a rendered line inside the terminal width is what prevents wrapping. For the progress tree a wrapped line desyncs the cursor-up redraw and floods the screen; for the commit graph it breaks the lane columns, since the continuation row carries no graph gutter.\n\n```go\nfunc ColorEnabled(w io.Writer, mode ColorMode) bool\n```\nColorEnabled reports whether color/ANSI escapes should be emitted to w.\n\n  - ColorNever or NO\\_COLOR/COMMITBRIEF\\_NO\\_COLOR env set → false\n  - ColorAlways → true (caller's choice, even when piped)\n  - ColorAuto → true only if w is a TTY on a terminal that processes ANSI\n\nTERM=dumb is treated as no-color even on a TTY: dumb terminals (emacs M-x shell, some IDE consoles, bare ptys) report as terminals but do NOT honor cursor-movement escapes. Letting the animated progress renderer run there makes every redraw append instead of overwrite — the spinner \"floods\" the screen with one repeated line per frame. Demoting to plain (one line per stage) keeps those terminals readable. An explicit \\`--color always\\` still overrides, for users who know their terminal.\n\n```go\nfunc Confirm(r io.Reader, w io.Writer, question string, opts AskOptions) (bool, error)\n```\nConfirm asks a yes/no question, defaulting to No. On an interactive terminal (opts.Interactive) it renders an arrow-key-selectable Yes/No toggle via huh, read from the controlling terminal directly. Otherwise it falls back to the line-based AskYesNo over r/w — the path tests and non-TTY pipelines exercise. AssumeYes/NonInteractive short-circuit before either path, so the interactive toggle never appears in CI.\n\n```go\nfunc EnableANSI(w io.Writer) error\n```\nEnableANSI applies platform-specific tweaks needed to render ANSI escapes (e.g. enabling VT processing on Windows 10+). No-op on POSIX.\n\n```go\nfunc IsStdinTTY(r io.Reader) bool\n```\nIsStdinTTY reports whether the given reader is a TTY. Used by the CLI to decide whether to set AskOptions.NonInteractive automatically.\n\n```go\nfunc PromptSuffix(catalog *i18n.Catalog) string\n```\nPromptSuffix returns the y/N choice suffix for prompts (\"[y/N](/y/N)\" or the catalog's localised form like \"[e/H](/e/H)\"). Falls back to English when catalog is nil or the key is missing.\n\n```go\nfunc Select(question string, labels []string) (int, error)\n```\nSelect renders an arrow-key single-choice list on the controlling terminal (input os.Stdin, output os.Stderr so a captured stdout stays clean) and returns the index of the chosen item. labels\\[i] is shown for item i; the first item is pre-selected. It is interactive-only — callers must guarantee a TTY (the \\`commit\\` command errors on non-TTY before reaching the selector). Returns an error if labels is empty or the form is aborted (e.g. Ctrl-C).\n\n```go\nfunc TerminalWidth(w io.Writer) int\n```\nTerminalWidth reports the writer's terminal width in columns, or 0 when it cannot be determined — a non-file writer (a test buffer, a pipe), a redirected stream, or a platform that refuses the query.\n\n\\*\\*0 means \"unknown\", not \"zero columns\".\\*\\* Callers must treat it as \"do not clip\" rather than \"clip everything away\"; both the progress tree and the commit-graph renderer rely on that reading.\n\nThe width is a snapshot: nothing here watches SIGWINCH, so a caller that holds the value across a resize will be working from a stale number. That is deliberate — every consumer renders in one pass, and re-querying per line would cost a syscall per row for no benefit.\n\n## Types\n\n```go\ntype AskOptions struct {\n\tAssumeYes      bool\n\tNonInteractive bool\n\n\t// Interactive, when true, makes Confirm render an arrow-key\n\t// Yes/No toggle (huh) read from the controlling terminal instead\n\t// of the line-based fallback. Callers derive it from\n\t// IsStdinTTY(os.Stdin) — it is NOT inferred from the reader,\n\t// because the review-scoped shared reader is a *bufio.Reader, not\n\t// the *os.File the TTY check needs. AssumeYes and NonInteractive\n\t// still take precedence. Has no effect on AskYesNo (line-only).\n\tInteractive bool\n\n\t// Catalog, when non-nil, controls the prompt suffix (\"[y/N]\" vs\n\t// \"[e/H]\") and the accepted-affirmative vocabulary\n\t// (common.yes_short / common.yes_long). When nil, falls back to\n\t// English defaults so existing callers that don't have a catalog\n\t// handy keep working — but EVERY interactive caller in the CLI\n\t// should pass one so non-English locales actually get their\n\t// native input accepted (see UC-14 in PATCH_ROADMAP).\n\t//\n\t// The EN forms (\"y\"/\"yes\") are accepted unconditionally regardless\n\t// of catalog, so a user typing English in a Turkish session also\n\t// proceeds.\n\tCatalog *i18n.Catalog\n\n\t// DefaultYes flips the pre-selected answer to Yes. In the interactive\n\t// (huh) path the toggle starts on the affirmative button; in the\n\t// line-based path an empty answer is treated as yes. Off by default so\n\t// every existing caller keeps the safe default-to-No behaviour. Used by\n\t// the `commit` command, whose confirm defaults to Yes (ADR-0019).\n\tDefaultYes bool\n}\n```\n\n```go\ntype ColorMode int\n```\n\n```go\nconst (\n\tColorAuto ColorMode = iota\n\tColorAlways\n\tColorNever\n)\n```\n\n```go\nfunc ParseColorMode(s string) ColorMode\n```\n\n```go\ntype Progress struct {\n\t// contains filtered or unexported fields\n}\n```\nProgress is the staged-spinner driving the review pipeline's long-running operations. It renders a \\`tree\\` of stage lines on a single writer (typically stderr), animating the leading \\`⏺\\` glyph on the \\*currently active\\* stage and freezing prior stages with a terminal-state color (green for Finish, red for Fail, muted for Soft).\n\nThree operating modes, decided at construction:\n\n  - \\*\\*Animated\\*\\* — TTY writer + colors enabled. Full breathing-dot animation, ANSI cursor escapes to redraw the tree, multi-line output. The natural mode for interactive terminals.\n  - \\*\\*Plain\\*\\* — non-TTY writer (CI, pipe) but not silent. One line per stage transition (\\`\\[start]\\`, \\`\\[done]\\`, \\`\\[info]\\`, \\`\\[fail]\\`). No animation. Useful for CI logs.\n  - \\*\\*Silent\\*\\* — caller opts out (Quiet=true). No output at all.\n\nThe mode is fixed for the lifetime of the Progress; callers don't need to branch on TTY state at each call.\n\nConcurrency: Start/Info/Finish/Fail/Soft are safe to call from a single goroutine driving the pipeline. The animation lives in its own goroutine that reads the stage list under a mutex.\n\n```go\nfunc NewProgress(w io.Writer, mode ColorMode, quiet bool) *Progress\n```\nNewProgress returns a Progress configured for the given writer. The Animated mode requires a TTY writer and colors enabled (ColorAuto + no NO\\_COLOR env, or ColorAlways). On non-TTY or NO\\_COLOR, falls back to Plain mode. Set Quiet=true to suppress every output mode.\n\n```go\nfunc (p *Progress) Clear()\n```\nClear stops the animation and erases the rendered progress tree from the terminal. Use this when downstream output (cards / JSON / markdown body) is about to take over the screen and the per-stage breadcrumbs would be redundant clutter — the rendered output is itself proof the pipeline completed.\n\nIn plain mode (non-TTY) Clear is a no-op: those per-stage lines already shipped on each Start/Info/Finish call, are useful in CI logs, and aren't visually redundant the way a fixed-viewport tree is. In silent mode there is nothing to erase. Idempotent.\n\n```go\nfunc (p *Progress) Close()\n```\nClose stops the animation goroutine, ensuring the final frame is rendered (so completed stages stay on screen) and the cursor is restored to a known column. Idempotent.\n\nUse Close when the progress tree is the user's primary feedback (empty-diff \\`no\\_changes\\` path, provider-error path). Use Clear instead when downstream output — rendered cards, JSON, markdown — will take over the screen and the tree would just be clutter.\n\n```go\nfunc (p *Progress) Fail(err error)\n```\nFail marks the current stage as failed (red ⏺) and emits the error indented below it on the next render.\n\n```go\nfunc (p *Progress) Finish()\n```\nFinish marks the current stage as completed (green ⏺).\n\n```go\nfunc (p *Progress) Info(label string)\n```\nInfo appends a static informational line (no animated glyph, no terminal state). Used for stats lines like \"36 files +1233 -34\".\n\n```go\nfunc (p *Progress) InfoSub(label string)\n```\nInfoSub appends a static info line that belongs to a sub-list under the preceding line — e.g. the per-file entries below a \"Detected N staged files\" header. In animated mode the trunk separator (\\`│\\`) that normally sits between adjacent stages is suppressed \\*before\\* a sub line, so the items cluster tightly under their header instead of each getting a blank breather. In plain mode it is identical to Info.\n\n```go\nfunc (p *Progress) Pause()\n```\nPause stops the animation loop and clears the in-progress render so the terminal is handed back to the caller (e.g. an interactive cost prompt). The recorded stage list is preserved; Resume continues from where it left off.\n\n```go\nfunc (p *Progress) Resume()\n```\nResume restarts the animation after Pause. No-op if not paused.\n\n```go\nfunc (p *Progress) Soft()\n```\nSoft marks the current stage as completed with a neutral muted dot. Used when the operation produced a result that wasn't an outright success but isn't an error either — e.g. the first attempt of a retry-once pipeline.\n\n```go\nfunc (p *Progress) Start(label string)\n```\nStart appends a new active stage, finalizing the previous stage with Done (green) state. If no animation goroutine is running yet, one is spawned.\n\n","path":"github.com/CommitBrief/commitbrief/internal/ui","name":"ui","synopsis":"","isRedistributable":true}
