Documentation
¶
Overview ¶
Package ui provides common UI components for the miren CLI
Index ¶
- Constants
- func BriefId(e entity.AttrGetter) string
- func CleanEntityID(id string) string
- func CleanStatus(status string) string
- func Completed(str string, args ...any) string
- func Confirm(opts ...ConfirmOption) (bool, error)
- func DisplayAppVersion(version string) string
- func DisplayShortID(shortID, fullID string) string
- func DisplayStatus(status string) string
- func FriendlyId(e entity.AttrGetter) string
- func Hyperlink(url, text string) string
- func HyperlinkStyled(url, text string, color int) string
- func IsInteractive() bool
- func IsTTY() bool
- func PromptForInput(opts ...PromptOption) (string, error)
- func RenderMarkdownLink(s string, color int) string
- func Run(prefix string, cmd *exec.Cmd) error
- func TerminalWidth() int
- type Column
- type ColumnBuilder
- type ColumnHint
- type ConfirmOption
- type Definition
- type DefinitionDetail
- type DefinitionList
- type DefinitionListOption
- type DefinitionListStyles
- type Hint
- type List
- type NamedValue
- type NamedValueList
- type NamedValueOption
- type NamedValueStyles
- type PickerItem
- type PickerModel
- type PickerOption
- type PromptOption
- type Row
- type SimplePickerItem
- type Table
- type TableOption
- type TablePickerItem
- type TableStyles
- type TerminalError
- type ValueType
Constants ¶
const ( Checkmark = "\u2713" Play = "\u25B6" )
const Indent = " │"
Variables ¶
This section is empty.
Functions ¶
func BriefId ¶ added in v0.7.0
func BriefId(e entity.AttrGetter) string
BriefId returns the shortest usable identifier for an entity: short-id > name > full id.
func CleanEntityID ¶
CleanEntityID removes common entity type prefixes from entity IDs for cleaner display. For example: "sandbox/sb-ABC123" -> "sb-ABC123", "app_version/meet-vXYZ" -> "meet-vXYZ"
func CleanStatus ¶
CleanStatus removes the "status." prefix from a status string without applying color.
func Confirm ¶
func Confirm(opts ...ConfirmOption) (bool, error)
Confirm displays a yes/no confirmation prompt
func DisplayAppVersion ¶
DisplayAppVersion formats an app version string by removing prefixes and bolding the app name. For example: "app_version/meet-vXYZ123" -> "**meet**-vXYZ123" (where **meet** is bold)
func DisplayShortID ¶ added in v0.7.0
DisplayShortID returns the short ID if available, otherwise falls back to CleanEntityID.
func DisplayStatus ¶
DisplayStatus returns a colored version of the status string based on common status values. It also removes the "status." prefix if present.
func FriendlyId ¶ added in v0.7.0
func FriendlyId(e entity.AttrGetter) string
FriendlyId returns the most human-readable identifier: name > short-id > full id.
func Hyperlink ¶ added in v0.7.0
Hyperlink creates a clickable terminal hyperlink using the OSC 8 escape sequence with dotted underline styling. Raw SGR sequences are used so the result can be safely combined with lipgloss-rendered text without interference.
When stdout is not a TTY, returns just the text with no escape sequences.
func HyperlinkStyled ¶ added in v0.7.0
HyperlinkStyled is like Hyperlink but also applies a foreground color (256-color index).
When stdout is not a TTY, returns just the text with no escape sequences.
func IsInteractive ¶
func IsInteractive() bool
IsInteractive checks if we're in an interactive terminal
func IsTTY ¶ added in v0.7.0
func IsTTY() bool
IsTTY reports whether stdout is connected to a terminal.
func PromptForInput ¶
func PromptForInput(opts ...PromptOption) (string, error)
PromptForInput displays an interactive text input prompt and returns the user's input
func RenderMarkdownLink ¶ added in v0.7.0
RenderMarkdownLink parses a markdown-style link "[text](url)" and renders it as a clickable terminal hyperlink with the given 256-color index.
When stdout is not a TTY, renders as "text (url)" for readability in pipes/logs. If the input isn't a valid markdown link, it's returned as-is.
func TerminalWidth ¶ added in v0.7.0
func TerminalWidth() int
TerminalWidth returns the current terminal width, or 0 if stdout is not a TTY.
Types ¶
type Column ¶
type Column struct {
Title string
Width int
NoTruncate bool // If true, this column won't be truncated when scaling
WordWrap bool // If true, text that exceeds Width is wrapped instead of truncated
}
Column defines a table column with title and width
func AutoSizeColumns ¶
func AutoSizeColumns(headers []string, rows []Row, builder *ColumnBuilder) []Column
AutoSizeColumns calculates optimal column widths based on content, respecting terminal width and column configuration hints. Pass nil for builder to use default behavior.
type ColumnBuilder ¶ added in v0.0.2
type ColumnBuilder struct {
// contains filtered or unexported fields
}
ColumnBuilder helps configure column options using a fluent API
func Columns ¶ added in v0.0.2
func Columns() *ColumnBuilder
Columns creates a new ColumnBuilder for configuring column options
func (*ColumnBuilder) MaxWidth ¶ added in v0.0.2
func (b *ColumnBuilder) MaxWidth(index, width int) *ColumnBuilder
MaxWidth sets the maximum width for a specific column
func (*ColumnBuilder) MinWidth ¶ added in v0.0.2
func (b *ColumnBuilder) MinWidth(index, width int) *ColumnBuilder
MinWidth sets the minimum width for a specific column when scaling
func (*ColumnBuilder) NoTruncate ¶ added in v0.0.2
func (b *ColumnBuilder) NoTruncate(indices ...int) *ColumnBuilder
NoTruncate marks the specified column indices as non-truncatable
func (*ColumnBuilder) WordWrap ¶ added in v0.4.0
func (b *ColumnBuilder) WordWrap(indices ...int) *ColumnBuilder
WordWrap marks the specified column indices as word-wrapping. Wrapped columns split text across multiple lines at word boundaries instead of truncating with an ellipsis.
type ColumnHint ¶ added in v0.0.2
type ColumnHint struct {
MaxWidth int // Maximum width (0 = no limit)
NoTruncate bool // If true, this column won't be scaled down
MinWidth int // Minimum width when scaling (0 = use default)
WordWrap bool // If true, wrap text instead of truncating
}
ColumnHint provides configuration hints for a specific column
type ConfirmOption ¶
type ConfirmOption func(*confirmConfig)
ConfirmOption configures a confirmation prompt
func WithAffirmative ¶
func WithAffirmative(text string) ConfirmOption
WithAffirmative sets the affirmative response text (default: "yes")
func WithDefault ¶
func WithDefault(defaultYes bool) ConfirmOption
WithDefault sets the default response when user just presses enter
func WithIndent ¶ added in v0.0.2
func WithIndent(indent string) ConfirmOption
WithIndent sets the indentation prefix for the prompt
func WithMessage ¶
func WithMessage(message string) ConfirmOption
WithMessage sets the confirmation message
func WithNegative ¶
func WithNegative(text string) ConfirmOption
WithNegative sets the negative response text (default: "no")
type Definition ¶ added in v0.3.1
type Definition struct {
Term string
Description string
Details []DefinitionDetail
}
Definition represents a single definition entry with a term, description, and optional details
type DefinitionDetail ¶ added in v0.3.1
DefinitionDetail represents a child item in a definition (displayed as a tree)
type DefinitionList ¶ added in v0.3.1
type DefinitionList struct {
// contains filtered or unexported fields
}
DefinitionList renders a list of definitions with tree-style details
func NewDefinitionList ¶ added in v0.3.1
func NewDefinitionList(items []Definition, opts ...DefinitionListOption) *DefinitionList
NewDefinitionList creates a new definition list
func (*DefinitionList) Render ¶ added in v0.3.1
func (d *DefinitionList) Render() string
Render generates the string representation
type DefinitionListOption ¶ added in v0.3.1
type DefinitionListOption func(*DefinitionList)
DefinitionListOption is a function that configures a DefinitionList
func WithDefinitionListStyles ¶ added in v0.3.1
func WithDefinitionListStyles(styles DefinitionListStyles) DefinitionListOption
WithDefinitionListStyles sets custom styles
func WithDefinitionListTitle ¶ added in v0.3.1
func WithDefinitionListTitle(title string) DefinitionListOption
WithDefinitionListTitle sets the title
type DefinitionListStyles ¶ added in v0.3.1
type DefinitionListStyles struct {
Title lipgloss.Style
Term lipgloss.Style
Description lipgloss.Style
DetailName lipgloss.Style
DetailType lipgloss.Style
Required lipgloss.Style
TreeLine lipgloss.Style
}
DefinitionListStyles contains the styling configuration
func DefaultDefinitionListStyles ¶ added in v0.3.1
func DefaultDefinitionListStyles() DefinitionListStyles
DefaultDefinitionListStyles returns the default styling
type Hint ¶ added in v0.3.1
type Hint struct {
// contains filtered or unexported fields
}
Hint renders a dimmed hint/tip message
type NamedValue ¶ added in v0.3.1
NamedValue represents a label-value pair for display
func NewNamedValue ¶ added in v0.3.1
func NewNamedValue(label string, value any) NamedValue
NewNamedValue creates a NamedValue with automatic type detection
type NamedValueList ¶ added in v0.3.1
type NamedValueList struct {
// contains filtered or unexported fields
}
NamedValueList renders a list of named values with right-aligned labels
func NewNamedValueList ¶ added in v0.3.1
func NewNamedValueList(items []NamedValue, opts ...NamedValueOption) *NamedValueList
NewNamedValueList creates a new named value list
func (*NamedValueList) Render ¶ added in v0.3.1
func (n *NamedValueList) Render() string
Render generates the string representation of the named value list
type NamedValueOption ¶ added in v0.3.1
type NamedValueOption func(*NamedValueList)
NamedValueOption is a function that configures a NamedValueList
func WithNamedValueStyles ¶ added in v0.3.1
func WithNamedValueStyles(styles NamedValueStyles) NamedValueOption
WithNamedValueStyles sets custom styles for the named value list
type NamedValueStyles ¶ added in v0.3.1
type NamedValueStyles struct {
Label lipgloss.Style
Separator string
StringValue lipgloss.Style
NumberValue lipgloss.Style
BoolValue lipgloss.Style
NullValue lipgloss.Style
OtherValue lipgloss.Style
}
NamedValueStyles contains the styling configuration for named values
func DefaultNamedValueStyles ¶ added in v0.3.1
func DefaultNamedValueStyles() NamedValueStyles
DefaultNamedValueStyles returns the default styling for named values
type PickerItem ¶
type PickerItem interface {
// Row returns the table row data for this item
Row() []string
// ID returns a unique identifier for this item
ID() string
}
PickerItem represents an item that can be selected in the picker
func RunPicker ¶
func RunPicker(items []PickerItem, opts ...PickerOption) (PickerItem, error)
RunPicker runs an interactive picker and returns the selected item
type PickerModel ¶
type PickerModel struct {
Title string
Headers []string
Items []PickerItem
Selected PickerItem
Cancelled bool
// Optional filter function to disable certain items
IsDisabled func(item PickerItem) bool
// Optional message for disabled items
DisabledMessage string
// contains filtered or unexported fields
}
PickerModel is a table-based picker for selecting from a list of items
func NewPicker ¶
func NewPicker(items []PickerItem, opts ...PickerOption) *PickerModel
NewPicker creates a new picker model with the given options
func (*PickerModel) Init ¶
func (m *PickerModel) Init() tea.Cmd
func (*PickerModel) SetCursor ¶
func (m *PickerModel) SetCursor(index int)
SetCursor sets the cursor to the specified index
func (*PickerModel) View ¶
func (m *PickerModel) View() string
type PickerOption ¶
type PickerOption func(*PickerModel)
Picker configuration options
func WithDisabledCheck ¶
func WithDisabledCheck(check func(PickerItem) bool, message string) PickerOption
WithDisabledCheck sets a function to determine if items are disabled
func WithFooter ¶
func WithFooter(footer string) PickerOption
WithFooter sets the picker footer text
func WithHeaders ¶
func WithHeaders(headers []string) PickerOption
WithHeaders sets the table headers for the picker
type PromptOption ¶
type PromptOption func(*promptConfig)
PromptOption configures a text input prompt
func WithCharLimit ¶
func WithCharLimit(limit int) PromptOption
WithCharLimit sets the character limit (0 for unlimited)
func WithPlaceholder ¶
func WithPlaceholder(placeholder string) PromptOption
WithPlaceholder sets the placeholder text
func WithSensitive ¶
func WithSensitive(sensitive bool) PromptOption
WithSensitive makes the input masked (for passwords/secrets)
type SimplePickerItem ¶
SimplePickerItem is a basic implementation of PickerItem for single-column pickers
func (SimplePickerItem) ID ¶
func (s SimplePickerItem) ID() string
func (SimplePickerItem) Row ¶
func (s SimplePickerItem) Row() []string
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a simple, non-interactive table for CLI output
func NewTable ¶
func NewTable(opts ...TableOption) *Table
NewTable creates a new table with the given options
type TableOption ¶
type TableOption func(*Table)
TableOption is a function that configures a table
func WithColumns ¶
func WithColumns(cols []Column) TableOption
WithColumns sets the columns for the table
func WithStyles ¶
func WithStyles(styles TableStyles) TableOption
WithStyles sets custom styles for the table
func WithTableTitle ¶ added in v0.4.0
func WithTableTitle(title string) TableOption
WithTableTitle sets a title displayed above the table header
type TablePickerItem ¶
TablePickerItem is a multi-column implementation of PickerItem
func (TablePickerItem) ID ¶
func (t TablePickerItem) ID() string
func (TablePickerItem) Row ¶
func (t TablePickerItem) Row() []string
type TableStyles ¶
TableStyles contains the styling configuration for the table
func DefaultTableStyles ¶
func DefaultTableStyles() TableStyles
DefaultTableStyles returns the default styling for tables
type TerminalError ¶ added in v0.7.0
TerminalError is an optional interface for errors that can render a rich, human-friendly representation to a terminal. Errors that implement this interface get colorized, multi-line output with source context when displayed through the CLI.
The Error() method should still return a plain-text representation suitable for logging and wrapping. WriteForTerminal provides the enhanced version for interactive use.
This follows the same pattern as io.WriterTo and http.Flusher — a type assertion at the display boundary unlocks richer behavior.
Design note: this interface is rendering-only. The underlying error type should carry structured data (source locations, hints, etc.) as exported fields so that the data can be serialized over RPC. Client-side code can then reconstruct a TerminalError from the wire data for local rendering.