Documentation
¶
Overview ¶
Package ui provides common UI components for the miren CLI
Index ¶
- Constants
- 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 DisplayStatus(status string) string
- func IsInteractive() bool
- func PromptForInput(opts ...PromptOption) (string, error)
- func Run(prefix string, cmd *exec.Cmd) error
- type Column
- type ColumnBuilder
- type ColumnHint
- type ConfirmOption
- type List
- type PickerItem
- type PickerModel
- type PickerOption
- type PromptOption
- type Row
- type SimplePickerItem
- type Table
- type TableOption
- type TablePickerItem
- type TableStyles
Constants ¶
const ( Checkmark = "\u2713" Play = "\u25B6" )
const Indent = " │"
Variables ¶
This section is empty.
Functions ¶
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 DisplayStatus ¶
DisplayStatus returns a colored version of the status string based on common status values. It also removes the "status." prefix if present.
func IsInteractive ¶
func IsInteractive() bool
IsInteractive checks if we're in an interactive terminal
func PromptForInput ¶
func PromptForInput(opts ...PromptOption) (string, error)
PromptForInput displays an interactive text input prompt and returns the user's input
Types ¶
type Column ¶
type Column struct {
Title string
Width int
NoTruncate bool // If true, this column won't be truncated when scaling
}
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
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)
}
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 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
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