tui

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package tui owns the CLI's data-presentation contract and the theme it pushes into dry/tui at startup. Operational messaging (Info / Success / Warning / Error) is not wrapped here. Commands call the dry/tui helpers directly for those.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLITheme

func CLITheme() drytheme.Theme

CLITheme returns the safedep-cli theme. main() pushes this into dry/tui as the global default at startup, after which dry/tui Console helpers (Info / Success / Warning / Error / Print) pick it up.

Only warnings and errors carry color. Info and success render with the terminal's default foreground so routine messages do not compete visually with actionable ones.

func EnumToken added in v0.3.0

func EnumToken(enumString, prefix string) string

EnumToken converts a proto enum's String() form into a lowercase, hyphenated display token, shared by commands that render proto enums. It strips prefix, maps the unspecified/empty value to "unknown", lowercases, and turns underscores into hyphens. For example:

EnumToken("ANALYSIS_STATUS_IN_PROGRESS", "ANALYSIS_STATUS_") -> "in-progress"
EnumToken("BILLING_TIER_PROFESSIONAL", "BILLING_TIER_")       -> "professional"
EnumToken("ECOSYSTEM_UNSPECIFIED", "ECOSYSTEM_")              -> "unknown"

func EnumTokens added in v0.4.0

func EnumTokens(names map[int32]string, prefix string) []string

EnumTokens lists every resolvable display token for a generated `<Enum>_name` map, ordered by enum number so help text and error messages stay stable across builds. The unspecified value is excluded to match ParseEnumToken.

func IsInteractive added in v0.3.0

func IsInteractive() bool

IsInteractive reports whether the CLI can prompt the user and open a browser. It keys off the actual terminal state (stdin is a TTY, which prompt libraries need to read input) rather than the presentation mode, which is user- overridable via --output/SAFEDEP_OUTPUT and does not reflect whether a human is present. Agent mode is excluded outright so tool-driven runs never block on stdin.

func ParseEnumToken added in v0.4.0

func ParseEnumToken(names map[int32]string, prefix, token string) (int32, bool)

ParseEnumToken resolves a display token produced by EnumToken back to its proto enum number, using the generated `<Enum>_name` map. The unspecified value is never resolvable: it is the absence of a selection, so callers cannot ask for it by name.

ParseEnumToken(v1.ScanStatus_name, "SCAN_STATUS_", "queued") -> 3, true

Types

type Mode

type Mode string

Mode is the user-facing data-output selection. It governs only the data stream on stdout. Messaging on stderr (tui.Info/Success/...) is driven independently by dry/tui's own mode auto-detection.

const (
	ModeTable Mode = "table"
	ModePlain Mode = "plain"
	ModeJSON  Mode = "json"
)

func AutoMode

func AutoMode() Mode

AutoMode returns the auto-detected Mode for the current environment. dry/tui agent mode maps to JSON for data output; rich and plain map to their named equivalents.

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode validates a user-supplied --output value. Empty input auto-detects from dry/tui's terminal/agent/CI heuristics.

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer dispatches a Renderable to stdout in the active Mode.

func NewPrinter

func NewPrinter(mode Mode) *Printer

func (*Printer) Mode

func (p *Printer) Mode() Mode

func (*Printer) Print

func (p *Printer) Print(r Renderable) error

Print writes the Renderable to stdout in the printer's active Mode. JSON bytes are written verbatim with a trailing newline appended when the renderer did not include one.

type Renderable

type Renderable interface {
	RenderJSON() ([]byte, error)
	RenderTable() string
	RenderPlain() string
}

Renderable is implemented by command results that produce structured output. Each method emits the same data in a different format. The dispatcher (Printer.Print) picks one based on the active Mode.

Lists implement the same interface. RenderTable produces a table, RenderPlain emits a line per item, RenderJSON returns the encoded array. Pre-built helpers for common shapes are not provided yet.

Jump to

Keyboard shortcuts

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