cliui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package cliui owns terminal capability detection and human-facing rendering for the secondbox and secondbox-deploy commands. Domain and command packages pass typed values to this package; they do not construct terminal styles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(value string) string

Sanitize makes server-controlled values safe to place in a terminal view.

func WriteJSONPassthrough

func WriteJSONPassthrough(output io.Writer, validated []byte) error

WriteJSONPassthrough deliberately does not decode or normalize validated JSON.

Types

type Activity

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

Activity is a bounded lifecycle indicator. Complete must be called before any guest or subprocess stream is forwarded.

func (*Activity) Complete

func (activity *Activity) Complete(status Status, detail string) error

type Background

type Background string
const (
	BackgroundDark  Background = "dark"
	BackgroundLight Background = "light"
)

type Capabilities

type Capabilities struct {
	Input      StreamCapabilities
	Output     StreamCapabilities
	Diagnostic StreamCapabilities
	Unicode    bool
	Dumb       bool
	CI         bool
	NoColor    bool
	Accessible bool
}

Capabilities intentionally describes stdin, stdout, and stderr separately. A redirected stdout must never disable a progress display on a TTY stderr.

func ForWriter

func ForWriter(output, diagnostic io.Writer) Capabilities

ForWriter provides deterministic non-TTY defaults for injected buffers.

func Probe

func Probe(options ProbeOptions) Capabilities

type ColorMode

type ColorMode string

ColorMode controls ANSI color independently of the output representation.

const (
	ColorAuto   ColorMode = "auto"
	ColorAlways ColorMode = "always"
	ColorNever  ColorMode = "never"
)

func ParseColorMode

func ParseColorMode(value string) (ColorMode, error)

type ColorProfile

type ColorProfile string
const (
	ProfileASCII     ColorProfile = "ascii"
	ProfileANSI      ColorProfile = "ansi"
	ProfileANSI256   ColorProfile = "ansi256"
	ProfileTrueColor ColorProfile = "truecolor"
)

type Column

type Column struct {
	Key      string
	Title    string
	Priority int
	MinWidth int
}

type CommandContract

type CommandContract struct {
	Command    string
	Output     OutputKind
	ReadsStdin bool
	LongLived  bool
	ExitOwner  string
}

CommandContract is the reviewable inventory used to prevent a new command from accidentally gaining presentation bytes.

type FieldKind

type FieldKind string
const (
	FieldText    FieldKind = "text"
	FieldSecret  FieldKind = "secret"
	FieldSelect  FieldKind = "select"
	FieldConfirm FieldKind = "confirm"
)

type FieldSpec

type FieldSpec struct {
	Kind               FieldKind
	Title              string
	Description        string
	StringValue        *string
	BoolValue          *bool
	Options            []Option
	ValidateString     func(string) error
	RequireAffirmative bool
}

type Form

type Form interface {
	Run(context.Context, FormHandles) error
}

Form is the command-facing boundary. Tests and non-interactive planners can inject an implementation without importing Charm.

type FormHandles

type FormHandles struct {
	Input      io.Reader
	Output     io.Writer
	Width      int
	Accessible bool
	Dark       bool
}

type GroupSpec

type GroupSpec struct {
	Title  string
	Fields []FieldSpec
}

type Help

type Help struct {
	Title    string
	Usage    string
	Commands []Pair
	Options  []Pair
	Footer   string
}

type HuhForm

type HuhForm struct{ Groups []GroupSpec }

func AdvancedSettingsForm

func AdvancedSettingsForm(bindings []TextBinding) HuhForm

func CapacityReviewForm

func CapacityReviewForm(summary string, accepted *bool) HuhForm

func FinalInstallConfirmationForm

func FinalInstallConfirmationForm(review string, accepted *bool) HuhForm

func PurgeConfirmationForm

func PurgeConfirmationForm(expected string, answer *string) HuhForm

func ResumeSelectionForm

func ResumeSelectionForm(options []Option, target *string) HuhForm

func RetentionChoiceForm

func RetentionChoiceForm(target *string) HuhForm

func StandardBundleSelectionForm

func StandardBundleSelectionForm(accepted *bool) HuhForm

func UninstallConfirmationForm

func UninstallConfirmationForm(review string, accepted *bool) HuhForm

func WorkspaceChoiceForm

func WorkspaceChoiceForm(options []Option, target *string) HuhForm

func (HuhForm) Run

func (spec HuhForm) Run(ctx context.Context, handles FormHandles) error

type Option

type Option struct{ Label, Value string }

type OutputKind

type OutputKind string

OutputKind records a command's permanent stdout contract.

const (
	OutputBoundedHuman OutputKind = "bounded-human"
	OutputMachineJSON  OutputKind = "machine-json"
	OutputRawBytes     OutputKind = "raw-bytes"
	OutputGuestStream  OutputKind = "guest-stream"
	OutputSubprocess   OutputKind = "subprocess"
)

type OutputMode

type OutputMode string

OutputMode selects the representation written by bounded commands.

const (
	OutputAuto  OutputMode = "auto"
	OutputJSON  OutputMode = "json"
	OutputPlain OutputMode = "plain"
)

func ParseOutputMode

func ParseOutputMode(value string) (OutputMode, error)

type Pair

type Pair struct{ Key, Value string }

type Phase

type Phase struct {
	Name, Detail string
	Status       Status
}

type ProbeOptions

type ProbeOptions struct {
	Input          *os.File
	Output         *os.File
	Diagnostic     *os.File
	Environment    []string
	Size           func(fd int) (width, height int, err error)
	IsTerminal     func(fd int) bool
	ColorProfile   func(output io.Writer, environment []string) colorprofile.Profile
	DarkBackground func(input, output *os.File) bool
}

type Renderer

type Renderer struct {
	Output       io.Writer
	Diagnostic   io.Writer
	Capabilities Capabilities
	OutputMode   OutputMode
	ColorMode    ColorMode
}

func (Renderer) FormatHelp

func (renderer Renderer) FormatHelp(help Help) string

func (Renderer) HumanOutput

func (renderer Renderer) HumanOutput() bool

func (Renderer) StartActivity

func (renderer Renderer) StartActivity(ctx context.Context, name string) (*Activity, error)

func (Renderer) StyledDiagnostic

func (renderer Renderer) StyledDiagnostic() bool

func (Renderer) StyledOutput

func (renderer Renderer) StyledOutput() bool

func (Renderer) WriteDeterminate

func (renderer Renderer) WriteDeterminate(label string, current, total int64) error

WriteDeterminate writes one bounded progress snapshot. TTY diagnostics use the Bubbles progress renderer; redirected diagnostics receive plain counts.

func (Renderer) WriteError

func (renderer Renderer) WriteError(problem error, hint string) error

func (Renderer) WriteHelp

func (renderer Renderer) WriteHelp(help Help) error

func (Renderer) WritePhases

func (renderer Renderer) WritePhases(phases []Phase) error

func (Renderer) WriteSummary

func (renderer Renderer) WriteSummary(summary Summary) error

func (Renderer) WriteTable

func (renderer Renderer) WriteTable(table Table) error

type Row

type Row map[string]string

type Status

type Status string
const (
	StatusPending  Status = "pending"
	StatusActive   Status = "active"
	StatusComplete Status = "complete"
	StatusWarning  Status = "warning"
	StatusFailed   Status = "failed"
)

type StreamCapabilities

type StreamCapabilities struct {
	TTY        bool
	Width      int
	Height     int
	Color      ColorProfile
	Background Background
}

type Summary

type Summary struct {
	Title    string
	Status   Status
	Pairs    []Pair
	Warnings []string
	Next     string
}

type Table

type Table struct {
	Columns            []Column
	Rows               []Row
	Empty              string
	ContinuationCursor string
}

type TextBinding

type TextBinding struct {
	Title       string
	Description string
	Value       *string
	Validate    func(string) error
}

TextBinding binds one reviewed advanced installer value. The installer owns the value and validation; the UI owns only its presentation.

type Theme

type Theme struct {
	Accent  lipgloss.Style
	Primary lipgloss.Style
	Muted   lipgloss.Style
	Success lipgloss.Style
	Warning lipgloss.Style
	Error   lipgloss.Style
}

func NewTheme

func NewTheme(capability StreamCapabilities, styled bool) Theme

Jump to

Keyboard shortcuts

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