tui

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Colors
	ColorSuccess = lipgloss.Color("2")
	ColorError   = lipgloss.Color("1")
	ColorWarn    = lipgloss.Color("3")
	ColorInfo    = lipgloss.Color("4")
	ColorMuted   = lipgloss.Color("8")
	ColorPrimary = lipgloss.Color("63") // Matches standard EnvCrypt color

	// Base Styles
	StyleSuccess = lipgloss.NewStyle().Foreground(ColorSuccess)
	StyleError   = lipgloss.NewStyle().Foreground(ColorError)
	StyleWarn    = lipgloss.NewStyle().Foreground(ColorWarn)
	StyleInfo    = lipgloss.NewStyle().Foreground(ColorInfo)
	StyleMuted   = lipgloss.NewStyle().Foreground(ColorMuted)
	StylePrimary = lipgloss.NewStyle().Foreground(ColorPrimary)

	// Icons
	IconCheck = StyleSuccess.Render("[✓]")
	IconCross = StyleError.Render("[x]")
	IconWarn  = StyleWarn.Render("[!]")
	IconInfo  = StyleInfo.Render(">")

	// Plain-mode icons (no ANSI)
	PlainIconCheck = "[✓]"
	PlainIconCross = "[x]"
	PlainIconWarn  = "[!]"
	PlainIconInfo  = ">"

	// Structural Styles
	HeaderStyle = lipgloss.NewStyle().Foreground(ColorMuted).Bold(true)

	BoxStyleWarn = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder()).
					BorderForeground(ColorWarn).
					Padding(1).
					MarginTop(1)

	BoxStylePrimary = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder()).
					BorderForeground(ColorPrimary).
					Padding(1).
					MarginTop(1)

	// Centralised navigation hint strings
	TableNavHint  = "↑/↓ to navigate  •  q to quit"
	PickerNavHint = "↑/↓ to navigate  •  enter to select  •  esc to cancel"
	FormNavHint   = "enter to confirm  •  esc to cancel"
)
View Source
var ErrCancelled = errors.New("operation cancelled")

ErrCancelled is returned when the user aborts an operation.

Functions

func Cancelled added in v1.4.0

func Cancelled() error

Cancelled prints a standardised cancellation message and returns ErrCancelled.

func ColorEnabled added in v1.4.0

func ColorEnabled() bool

ColorEnabled returns whether ANSI color output is allowed.

func ConfirmDangerousAction

func ConfirmDangerousAction(prompt, expected string, force ...bool) bool

ConfirmDangerousAction prompts the user for confirmation. If force is true, the confirmation is skipped.

func ConfirmOverwrite

func ConfirmOverwrite(path string) bool

func Error

func Error(msg string, err error, hints ...string) error

Error formats an error for display. Supports an optional hint string.

func ErrorWithHint added in v1.4.0

func ErrorWithHint(msg string, err error, hint string) error

ErrorWithHint renders an error with an actionable hint.

func Info

func Info(msg string)

Info prints an informational message, dispatched by output mode.

func InitOutput added in v1.4.0

func InitOutput(jsonMode, noColor, quiet bool)

InitOutput configures the global output mode. Call once from root PersistentPreRun.

func IsInteractive added in v1.1.1

func IsInteractive() bool

IsInteractive returns true when the CLI should use full interactive TUI. Retained for backward compatibility — delegates to the output mode system.

func IsQuiet added in v1.4.0

func IsQuiet() bool

IsQuiet returns whether --quiet is active.

func JSONData added in v1.4.0

func JSONData(v any)

JSONData emits arbitrary structured data as JSON to stdout.

func JSONMessage added in v1.4.0

func JSONMessage(level string, msg string)

JSONMessage emits a single structured JSON object to stdout.

func MapAPIError added in v1.4.0

func MapAPIError(detail *APIErrorDetail) error

MapAPIError converts an APIErrorDetail into a user-friendly error with hint.

func PadRight

func PadRight(s string, width int) string

func PlainTimestamp added in v1.4.0

func PlainTimestamp() string

PlainTimestamp returns a bracketed timestamp for plain mode log lines.

func PrintEnvSummary

func PrintEnvSummary(env map[string]string)

func PrintServiceRoleDetail

func PrintServiceRoleDetail(role *config.ServiceRole)

func PrintServiceRolePermissions

func PrintServiceRolePermissions(perm *config.ServiceRolePermsResponse, repoPrincipal string)

func PrintServiceRoleSecret

func PrintServiceRoleSecret(keyPair *config.ServiceRoleKeyPair)

func PromptWithDefault

func PromptWithDefault(label, defaultVal string) string

func RenderBanner added in v1.4.0

func RenderBanner() string

RenderBanner returns a high-fidelity ASCII/styled banner for the CLI.

func RenderDiff

func RenderDiff(diff cryptoutils.DiffingResult, oldMap, newMap map[string]string, showSecrets bool)

func RunActionWithSpinner

func RunActionWithSpinner(title string, action func() error) error

RunActionWithSpinner executes an action with a spinner in interactive mode, a static progress line in plain mode, or silently in JSON mode.

func RunAuditTable added in v1.5.0

func RunAuditTable(logs []config.AuditEntry, total int) error

func RunEnvPicker

func RunEnvPicker(projectName string) (string, error)

func RunForm

func RunForm(fields []FormField, prefills []string) ([]string, error)

func RunPicker

func RunPicker(title string, items []string) (string, error)

func RunPickerWithDefault added in v1.7.0

func RunPickerWithDefault(title string, items []string, defaultItem string) (string, error)

func RunProjectsTable

func RunProjectsTable(projects []config.Project) error

func RunServiceRolesTable

func RunServiceRolesTable(roles []config.ServiceRole) error

func SetNoTable added in v1.4.0

func SetNoTable(v bool)

func Spacer

func Spacer()

Spacer prints a blank line (suppressed in JSON/quiet mode).

func StripANSI

func StripANSI(s string) string

func Success

func Success(msg string)

Success prints a success message, dispatched by output mode.

func Truncate

func Truncate(s string, max int) string

func ValidateEmail added in v1.4.0

func ValidateEmail(s string) error

ValidateEmail checks for a valid email format.

func ValidateFileExists added in v1.4.0

func ValidateFileExists(s string) error

ValidateFileExists checks that a file exists at the given path.

func ValidateProjectName added in v1.4.0

func ValidateProjectName(s string) error

ValidateProjectName checks that a project name follows naming rules.

func VisibleLen

func VisibleLen(s string) int

func Warn

func Warn(msg string)

Warn prints a warning message, dispatched by output mode.

Types

type APIErrorDetail added in v1.4.0

type APIErrorDetail struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Hint    string `json:"hint"`
}

APIErrorDetail represents the structured error returned by the server.

type FormField

type FormField struct {
	Label    string
	Secret   bool
	Required bool
	Validate func(string) error // optional validation function
}

FormField defines a single input field in a form.

type OutputMode added in v1.4.0

type OutputMode int

OutputMode determines how the CLI renders output.

const (
	ModeInteractive OutputMode = iota
	ModePlain
	ModeJSON
)

func Mode added in v1.4.0

func Mode() OutputMode

Mode returns the active output mode.

type TermLevel added in v1.4.0

type TermLevel int

TermLevel describes the terminal's capability.

const (
	TermFull    TermLevel = iota // Full TTY: colors, cursor control, animations
	TermLimited                  // Limited TTY: colors but no animations (e.g. TERM=dumb)
	TermNone                     // Non-TTY: pipes, CI, scripts
)

func DetectTermLevel added in v1.4.0

func DetectTermLevel() TermLevel

DetectTermLevel inspects stdout to determine terminal capabilities.

Jump to

Keyboard shortcuts

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