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 ¶
- func CLITheme() drytheme.Theme
- func EnumToken(enumString, prefix string) string
- func EnumTokens(names map[int32]string, prefix string) []string
- func EscapeCells(rows [][]string) [][]string
- func EscapeLine(s string) string
- func EscapeText(s string) string
- func IsInteractive() bool
- func ParseEnumToken(names map[int32]string, prefix, token string) (int32, bool)
- func PlainRow(fields ...string) string
- func RunEditor(ctx context.Context, command, path string) error
- type Mode
- type Printer
- type Renderable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CLITheme ¶
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
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
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 EscapeCells ¶ added in v0.11.0
EscapeCells escapes each cell of each table row as one line.
func EscapeLine ¶ added in v0.11.0
EscapeLine returns s as one line. It shows each control character, line breaks and tabs included, and each bidirectional format character as an escape, for example \n, \x1b or \u202e. Invalid UTF-8 becomes U+FFFD.
func EscapeText ¶ added in v0.11.0
EscapeText returns s with its line breaks kept. It escapes every other control character and each bidirectional format character.
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
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
func PlainRow ¶ added in v0.11.0
PlainRow escapes each field as one line and joins the fields with tabs, so a tab or a line break in a value never adds a column or a row.
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.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer dispatches a Renderable to stdout in the active Mode.
func NewPrinter ¶
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.