Documentation
¶
Overview ¶
Package presentation renders consistent, terminal-safe service command output.
Index ¶
- Variables
- func DividerLine(width int) string
- func RunLifecycle(ctx context.Context, input io.Reader, output io.Writer, ...) error
- func RunSelection(ctx context.Context, input io.Reader, output io.Writer, model *SelectionModel) ([]int, error)
- func RunSpinner(ctx context.Context, output io.Writer, label string, runner SpinnerRunner) error
- type ColorMode
- type Command
- type CommandGroup
- type LifecycleEvent
- type LifecycleGroup
- type LifecycleModel
- type LifecycleOperation
- type LifecycleRunner
- type LifecycleService
- type LifecycleStage
- type ProjectGroup
- type ProjectRowsOptions
- type Renderer
- func (renderer Renderer) Error(err error)
- func (renderer Renderer) Heading(title string, detail string)
- func (renderer Renderer) Help(version string, groups []CommandGroup)
- func (renderer Renderer) Interactive() bool
- func (renderer Renderer) Live() bool
- func (renderer Renderer) OperationHeading(title string, detail string)
- func (renderer Renderer) OperationStep(operation string, kind StepKind, subject string, detail string)
- func (renderer Renderer) ProjectRows(groups []ProjectGroup, options ProjectRowsOptions)
- func (renderer Renderer) Spacer()
- func (renderer Renderer) Step(kind StepKind, subject string, detail string)
- func (renderer Renderer) Table(headers []string, rows [][]string)
- func (renderer Renderer) Width() int
- func (renderer Renderer) Write(value []byte) (int, error)
- func (renderer Renderer) Writer() io.Writer
- type SelectionItem
- type SelectionModel
- func (model *SelectionModel) Cancel()
- func (model *SelectionModel) Cancelled() bool
- func (model *SelectionModel) Chosen() []int
- func (model *SelectionModel) Confirm()
- func (model *SelectionModel) Done() bool
- func (model *SelectionModel) MoveCursor(step int)
- func (model *SelectionModel) Render() string
- func (model *SelectionModel) SetAll(chosen bool)
- func (model *SelectionModel) SetHeight(terminalHeight int)
- func (model *SelectionModel) SetWidth(terminalWidth int)
- func (model *SelectionModel) Toggle()
- type SpinnerRunner
- type StepKind
Constants ¶
This section is empty.
Variables ¶
var ErrInterrupted = errors.New("operation interrupted")
ErrInterrupted reports that the user interrupted an interactive lifecycle operation after its runner completed graceful cleanup.
var ErrSelectionCancelled = fmt.Errorf("selection cancelled")
ErrSelectionCancelled reports that the list was closed without an answer, so the caller does nothing rather than doing everything.
Functions ¶
func DividerLine ¶
DividerLine returns a stable horizontal separator for compact command sections. Callers may apply their own color style around the returned text.
func RunLifecycle ¶
func RunLifecycle(ctx context.Context, input io.Reader, output io.Writer, operation LifecycleOperation, width int, run LifecycleRunner) error
RunLifecycle runs a lifecycle command through a compact inline Bubble Tea view. It restores the final footer after Bubble Tea releases its inline screen, preserving the completed snapshot in normal terminal scrollback.
func RunSelection ¶
func RunSelection(ctx context.Context, input io.Reader, output io.Writer, model *SelectionModel) ([]int, error)
RunSelection shows the rows, lets a person mark the ones they want, and returns the indices they marked.
It needs a terminal. A caller without one decides for itself what to do, since asking a question nobody can answer is worse than not asking.
func RunSpinner ¶
RunSpinner renders immediate animated feedback until runner returns. Callers must only use it for live terminal output.
Types ¶
type ColorMode ¶
type ColorMode string
ColorMode controls whether ANSI color sequences are emitted.
const ( // ColorAuto emits color only for an interactive terminal that has not opted // out through the NO_COLOR convention. ColorAuto ColorMode = "auto" // ColorAlways emits ANSI color sequences for terminals and redirected output. ColorAlways ColorMode = "always" // ColorNever keeps output free of ANSI control sequences. ColorNever ColorMode = "never" )
func ParseColorMode ¶
ParseColorMode validates a command-line color mode.
type CommandGroup ¶
CommandGroup keeps related CLI commands together in help output.
type LifecycleEvent ¶
type LifecycleEvent struct {
Key string
Name string
Stage LifecycleStage
Detail string
// Groups replaces the operation's project groups once a live command has
// discovered its global configuration.
Groups []LifecycleGroup
}
LifecycleEvent updates one stable service row. Key is optional for backwards-compatible single-project operations, where Name identifies the row.
type LifecycleGroup ¶
type LifecycleGroup struct {
Name string
Services []LifecycleService
}
LifecycleGroup keeps related lifecycle services below their explicit project identity while preserving stable service keys for progress updates.
type LifecycleModel ¶
type LifecycleModel struct {
// contains filtered or unexported fields
}
LifecycleModel is a renderable, deterministic lifecycle snapshot. It is separate from Bubble Tea so layout can be unit-tested without a terminal.
func NewLifecycleModel ¶
func NewLifecycleModel(operation LifecycleOperation, width int) *LifecycleModel
NewLifecycleModel creates a stable lifecycle view with one Pending row per selected service.
func (*LifecycleModel) Apply ¶
func (model *LifecycleModel) Apply(event LifecycleEvent)
Apply updates an existing row in place. Unknown rows are ignored because the operation is intentionally scoped to the services selected by the command.
func (*LifecycleModel) Render ¶
func (model *LifecycleModel) Render() string
Render produces the current compact lifecycle view at the configured width. Horizontal indentation groups the view without consuming vertical space.
type LifecycleOperation ¶
type LifecycleOperation struct {
Title string
Project string
Services []LifecycleService
Groups []LifecycleGroup
// HideTitle lets an inline lifecycle view continue a previously printed
// operation heading without repeating it.
HideTitle bool
// GroupServices renders lifecycle rows below their project identity. It allows
// a global operation to start its inline view before discovery has supplied
// the project groups.
GroupServices bool
// HideEndpoint switches the view to its two-column operation layout. That
// layout lets global port reassignment retain every project-qualified service
// label instead of truncating it for a redundant endpoint column.
HideEndpoint bool
}
LifecycleOperation supplies the title, project, and selected service rows for one start, stop, or restart command.
type LifecycleRunner ¶
type LifecycleRunner func(ctx context.Context, report func(LifecycleEvent)) error
LifecycleRunner performs a lifecycle command while forwarding each factual event to report. It must respect ctx cancellation.
type LifecycleService ¶
LifecycleService identifies one stable row in a lifecycle view. Key is optional for single-project operations, where Name remains the stable identifier.
type LifecycleStage ¶
type LifecycleStage string
LifecycleStage is the presentation-specific state of one managed service row. It is deliberately independent of runtime.ProgressStage.
const ( // LifecyclePending means no lifecycle event has been received yet. LifecyclePending LifecycleStage = "pending" // LifecycleInspecting means persisted process state is being inspected. LifecycleInspecting LifecycleStage = "inspecting" // LifecycleStopping means graceful shutdown is in progress. LifecycleStopping LifecycleStage = "stopping" // LifecycleStopped means the prior managed process has stopped. LifecycleStopped LifecycleStage = "stopped" // LifecycleStarting means a new isolated process is launching. LifecycleStarting LifecycleStage = "starting" // LifecycleWaiting means listener ownership and health are being checked. LifecycleWaiting LifecycleStage = "waiting" // LifecycleReady means the configured readiness boundary has passed. LifecycleReady LifecycleStage = "ready" // LifecycleFailed means the selected service could not complete its operation. LifecycleFailed LifecycleStage = "failed" )
type ProjectGroup ¶
ProjectGroup is one named collection of related command output rows. Rows retain their group order while their first cell is rendered alphabetically.
type ProjectRowsOptions ¶
type ProjectRowsOptions struct {
Indent int
ColumnGap int
MinimumColumnWidths []int
RenderProject func(string) string
RenderCell func(column int, value string) string
}
ProjectRowsOptions controls the compact, headerless layout shared by project-oriented command output.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer owns a single command's user-facing output. It deliberately keeps color and layout decisions separate from command and runtime logic.
func New ¶
New creates a renderer for writer. A non-file writer is treated as non-interactive so tests and piped output remain deterministic plain text.
func (Renderer) Help ¶
func (renderer Renderer) Help(version string, groups []CommandGroup)
Help renders structured command help. It intentionally receives command metadata rather than parsing a preformatted string, so plain and rich views cannot drift apart.
func (Renderer) Interactive ¶
Interactive reports whether the renderer writes to a terminal.
func (Renderer) Live ¶
Live reports whether a command may take control of an interactive terminal for an inline Bubble Tea view. Plain, piped, and explicitly color-disabled output must remain append-only text.
func (Renderer) OperationHeading ¶
OperationHeading renders the stable, one-time introduction for an operation that may later hand control to an inline lifecycle view.
func (Renderer) OperationStep ¶
func (renderer Renderer) OperationStep(operation string, kind StepKind, subject string, detail string)
OperationStep aligns its detail with the contextual detail in the matching operation heading. It avoids the extra indentation used by generic steps.
func (Renderer) ProjectRows ¶
func (renderer Renderer) ProjectRows(groups []ProjectGroup, options ProjectRowsOptions)
ProjectRows renders named groups with uniformly indented, headerless rows. It is intended for concise project and service summaries where repeating column headings would add noise.
func (Renderer) Spacer ¶
func (renderer Renderer) Spacer()
Spacer separates adjacent command output sections with one blank line.
func (Renderer) Table ¶
Table renders borderless, aligned columns. The same geometry is used for interactive and redirected output so tables remain scannable and scriptable.
func (Renderer) Width ¶
Width returns the active terminal width or a conservative default for redirected output and terminals whose size cannot be queried.
type SelectionItem ¶
type SelectionItem struct {
// Title is what the row is called, which for project discovery is the path.
Title string
// Detail says what would happen to it, such as the services that were found.
Detail string
// Chosen is whether the row is currently marked to be acted on.
Chosen bool
// Fixed marks a row that cannot be chosen, because there is nothing to do to
// it. It stays visible so the answer is complete rather than filtered.
Fixed bool
}
SelectionItem is one row a person moves through and decides on.
type SelectionModel ¶
type SelectionModel struct {
// contains filtered or unexported fields
}
SelectionModel holds a list of rows, which one the cursor is on, and how much of the list fits on screen.
It is separate from the Bubble Tea plumbing in selection_program.go so the behaviour can be exercised without a terminal, which is what the tests do.
func NewSelectionModel ¶
func NewSelectionModel(title string, prompt string, items []SelectionItem, width int) *SelectionModel
NewSelectionModel builds the list. Rows that cannot be chosen start unchosen whatever they were given, since choosing one would promise something that will not happen.
func (*SelectionModel) Cancel ¶
func (model *SelectionModel) Cancel()
Cancel ends the list with nothing marked.
func (*SelectionModel) Cancelled ¶
func (model *SelectionModel) Cancelled() bool
Cancelled reports whether the list ended without an answer.
func (*SelectionModel) Chosen ¶
func (model *SelectionModel) Chosen() []int
Chosen returns the indices of the marked rows, in the order they were given.
func (*SelectionModel) Confirm ¶
func (model *SelectionModel) Confirm()
Confirm ends the list with what is currently marked.
func (*SelectionModel) Done ¶
func (model *SelectionModel) Done() bool
Done reports whether the list has ended, either way.
func (*SelectionModel) MoveCursor ¶
func (model *SelectionModel) MoveCursor(step int)
MoveCursor moves by step rows, stopping at either end rather than wrapping, because wrapping in a long list loses the sense of where the ends are.
func (*SelectionModel) Render ¶
func (model *SelectionModel) Render() string
Render draws the list as it currently stands.
func (*SelectionModel) SetAll ¶
func (model *SelectionModel) SetAll(chosen bool)
SetAll marks or unmarks every row that can be chosen.
func (*SelectionModel) SetHeight ¶
func (model *SelectionModel) SetHeight(terminalHeight int)
SetHeight tells the list how many rows it may draw, which the terminal decides. Two lines go to the title and the footer and two more to the key hints.
func (*SelectionModel) SetWidth ¶
func (model *SelectionModel) SetWidth(terminalWidth int)
SetWidth tells the list how wide the terminal is.
func (*SelectionModel) Toggle ¶
func (model *SelectionModel) Toggle()
Toggle marks or unmarks the row under the cursor.
type SpinnerRunner ¶
SpinnerRunner performs the blocking operation displayed by RunSpinner.
type StepKind ¶
type StepKind string
StepKind determines the semantic color and label for an operation step.
const ( // StepInfo identifies an informative completed step. StepInfo StepKind = "info" // StepWorking identifies a lifecycle phase that is still in progress. StepWorking StepKind = "working" // StepSuccess identifies a successful operation result. StepSuccess StepKind = "success" // StepWarning identifies a non-fatal condition requiring attention. StepWarning StepKind = "warning" // StepFailure identifies an unsuccessful operation result. StepFailure StepKind = "failure" )