Documentation
¶
Overview ¶
Package cliui contains the terminal-facing presentation primitives shared by Overgent commands. It deliberately knows nothing about Projects, credentials, repositories, or the service protocol.
Index ¶
- Variables
- func FormatElapsed(duration time.Duration) string
- func IsTerminal(stream any) bool
- func Select(terminal Terminal, title, detail string, choices []Choice) (int, error)
- func Wrap(text string, width int) []string
- func WriteFields(writer io.Writer, width int, fields []Field) error
- type Choice
- type ColorMode
- type Field
- type Options
- type Output
- type OutputMode
- type Style
- type Terminal
- func (terminal Terminal) Animated() bool
- func (terminal Terminal) ColorEnabled() bool
- func (terminal Terminal) Err() io.Writer
- func (terminal Terminal) In() io.Reader
- func (terminal Terminal) InputIsTerminal() bool
- func (terminal Terminal) Interactive() bool
- func (terminal Terminal) Out() io.Writer
- func (terminal Terminal) OutputIsTerminal() bool
- func (terminal Terminal) Style(style Style, text string) string
- func (terminal Terminal) Symbol(unicodeValue, asciiValue string) string
- func (terminal Terminal) UnicodeEnabled() bool
- func (terminal Terminal) Width() int
- type UnicodeMode
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("selection cancelled")
Functions ¶
func FormatElapsed ¶
FormatElapsed implements the product-wide elapsed-time contract: 47s, 12m 16s, and 1h 04m. Negative durations are clamped to zero. Durations never use a colon because that reads as wall-clock time.
func IsTerminal ¶
IsTerminal checks real file-backed streams. Non-file readers and writers are deliberately non-interactive so buffers, pipes, and test doubles never cause an accidental prompt.
func Select ¶
Select presents a compact native terminal picker. It uses arrow keys (or j/k), Enter to accept, and Escape/q/Ctrl-C to cancel. Callers should retain a numbered-line fallback for non-interactive streams.
Types ¶
type ColorMode ¶
type ColorMode uint8
ColorMode controls ANSI styling. Auto is suitable for normal command use.
type Options ¶
type Options struct {
In io.Reader
Out io.Writer
Err io.Writer
LookupEnv func(string) (string, bool)
IsTerminal func(any) bool
Color ColorMode
Unicode UnicodeMode
DefaultWidth int
}
Options defines the streams and environment used for terminal detection. LookupEnv and IsTerminal are injectable so command tests never need to alter the process environment or depend on the terminal running the test suite.
type Output ¶
type Output struct {
Mode OutputMode
Out io.Writer
Err io.Writer
}
Output owns one command's output contract. Its writers are supplied by the caller; it never reads global process output or sends data elsewhere.
func NewOutput ¶
func NewOutput(terminal Terminal, mode OutputMode) Output
func (Output) EncodeLine ¶
EncodeLine writes one compact JSON value for a JSON Lines stream.
type OutputMode ¶
type OutputMode uint8
OutputMode distinguishes prose intended for a person from stable structured output intended for another program.
const ( OutputHuman OutputMode = iota OutputJSON OutputJSONLines )
func ParseOutputMode ¶
func ParseOutputMode(value string) (OutputMode, error)
ParseOutputMode converts the public flag spelling to a mode.
func (OutputMode) MachineReadable ¶
func (mode OutputMode) MachineReadable() bool
type Style ¶
type Style uint8
Style is intentionally limited to Overgent's status and hierarchy channels. Adding a severity rainbow here would violate the product design system.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is an immutable description of one command invocation's terminal.
func NewTerminal ¶
NewTerminal returns a terminal description with safe process defaults.
func (Terminal) Animated ¶
Animated reports whether the caller may rewrite the current line in place. It requires a real terminal and refuses a dumb one, where cursor control is not dependable. Callers must render a correct, complete result without it: in-place updating is an enhancement, never the only way a fact is shown.
func (Terminal) ColorEnabled ¶
ColorEnabled applies common CLI conventions: automatic color requires a TTY, is disabled by NO_COLOR even when its value is empty, and is disabled for a dumb terminal. An explicit ColorAlways overrides environment detection.
func (Terminal) InputIsTerminal ¶
InputIsTerminal reports whether input is an interactive terminal.
func (Terminal) Interactive ¶
Interactive is true only when both input and output are terminals. Callers should use this before prompting; output being a TTY alone is insufficient.
func (Terminal) OutputIsTerminal ¶
OutputIsTerminal reports whether human output is attached to a terminal.
func (Terminal) Style ¶
Style applies an ANSI style when color is enabled. The returned text always carries the same meaning without ANSI escapes.
func (Terminal) UnicodeEnabled ¶
UnicodeEnabled reports whether glyphs should use their Unicode form. Explicit C/POSIX or non-UTF locales get ASCII, as does TERM=dumb. A missing locale is treated as UTF-8 because Go strings and supported modern terminals are UTF-8; callers can always request UnicodeNever.
type UnicodeMode ¶
type UnicodeMode uint8
UnicodeMode controls whether presentation glyphs may use Unicode.
const ( UnicodeAuto UnicodeMode = iota UnicodeAlways UnicodeNever )