ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ui provides common UI components for the miren CLI

Index

Constants

View Source
const (
	Checkmark = "\u2713"
	Play      = "\u25B6"
)
View Source
const Indent = "  │"

Variables

This section is empty.

Functions

func CleanEntityID

func CleanEntityID(id string) string

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

func CleanStatus(status string) string

CleanStatus removes the "status." prefix from a status string without applying color.

func Completed

func Completed(str string, args ...any) string

func Confirm

func Confirm(opts ...ConfirmOption) (bool, error)

Confirm displays a yes/no confirmation prompt

func DisplayAppVersion

func DisplayAppVersion(version string) string

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

func DisplayStatus(status string) string

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

func Run

func Run(prefix string, cmd *exec.Cmd) error

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 List

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

func NewList

func NewList(w io.Writer) *List

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
	Footer    string

	// 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) Update

func (m *PickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

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

func WithTitle

func WithTitle(title string) PickerOption

WithTitle sets the picker title

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 WithLabel

func WithLabel(label string) PromptOption

WithLabel sets the prompt label

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)

func WithWidth

func WithWidth(width int) PromptOption

WithWidth sets the input field width

type Row

type Row []string

Row represents a single row of data in the table

type SimplePickerItem

type SimplePickerItem struct {
	Text   string
	Active bool
}

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

func (*Table) Render

func (t *Table) Render() string

Render generates the string representation of the table

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 WithRows

func WithRows(rows []Row) TableOption

WithRows sets the rows for the table

func WithStyles

func WithStyles(styles TableStyles) TableOption

WithStyles sets custom styles for the table

type TablePickerItem

type TablePickerItem struct {
	Columns []string
	ItemID  string
}

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

type TableStyles struct {
	Header lipgloss.Style
	Cell   lipgloss.Style
}

TableStyles contains the styling configuration for the table

func DefaultTableStyles

func DefaultTableStyles() TableStyles

DefaultTableStyles returns the default styling for tables

Jump to

Keyboard shortcuts

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