render

package
v0.0.0-...-d80aada Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package render provides UI component builders for dynamic rendering

Package render provides confirmation dialog UI component

Package render provides form input UI component

Package render provides list selection UI component

Package render provides table display UI component

Package render provides interactive UI tools for the assistant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuickConfirm

func QuickConfirm(message string, defaultYes bool, output io.Writer) (bool, error)

QuickConfirm provides a simple confirmation dialog.

Types

type Builder

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

Builder provides methods to construct UI components programmatically.

func NewBuilder

func NewBuilder(uiType string) *Builder

NewBuilder creates a new UI builder.

func (*Builder) Build

func (b *Builder) Build() UIRequest

Build finalizes and returns the UI request.

func (*Builder) WithDescription

func (b *Builder) WithDescription(desc string) *Builder

WithDescription sets the description.

func (*Builder) WithOptions

func (b *Builder) WithOptions(opts UIOptions) *Builder

WithOptions sets UI options.

func (*Builder) WithTitle

func (b *Builder) WithTitle(title string) *Builder

WithTitle sets the title.

type ConfirmBuilder

type ConfirmBuilder struct {
	*Builder
	// contains filtered or unexported fields
}

ConfirmBuilder provides fluent API for building confirmations.

func NewConfirmBuilder

func NewConfirmBuilder(message string) *ConfirmBuilder

NewConfirmBuilder creates a new confirmation builder.

func (*ConfirmBuilder) Build

func (b *ConfirmBuilder) Build() UIRequest

Build finalizes the confirmation request.

func (*ConfirmBuilder) DefaultNo

func (b *ConfirmBuilder) DefaultNo() *ConfirmBuilder

DefaultNo sets the default selection to No.

func (*ConfirmBuilder) DefaultYes

func (b *ConfirmBuilder) DefaultYes() *ConfirmBuilder

DefaultYes sets the default selection to Yes.

func (*ConfirmBuilder) WithTitle

func (b *ConfirmBuilder) WithTitle(title string) *ConfirmBuilder

WithTitle sets the title for confirmation.

type ConfirmData

type ConfirmData struct {
	Message string `json:"message"`
	Default bool   `json:"default,omitempty"`
}

ConfirmData contains data for confirmation dialog.

type ConfirmModel

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

ConfirmModel is a Bubble Tea model for confirmation dialogs.

func NewConfirmModel

func NewConfirmModel(req UIRequest) (*ConfirmModel, error)

NewConfirmModel creates a new confirmation dialog model.

func (*ConfirmModel) Init

func (m *ConfirmModel) Init() tea.Cmd

Init initializes the model.

func (*ConfirmModel) Result

func (m *ConfirmModel) Result() UIResponse

Result returns the confirmation result.

func (*ConfirmModel) Update

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

Update handles messages.

func (*ConfirmModel) View

func (m *ConfirmModel) View() string

View renders the confirmation dialog.

type ConfirmStyles

type ConfirmStyles struct {
	Title        lipgloss.Style
	Description  lipgloss.Style
	Message      lipgloss.Style
	Button       lipgloss.Style
	ActiveButton lipgloss.Style
	Help         lipgloss.Style
}

ConfirmStyles contains styles for confirmation dialog.

func DefaultConfirmStyles

func DefaultConfirmStyles() *ConfirmStyles

DefaultConfirmStyles returns default styles for confirmation.

type FormBuilder

type FormBuilder struct {
	*Builder
	// contains filtered or unexported fields
}

FormBuilder provides fluent API for building forms.

func NewFormBuilder

func NewFormBuilder() *FormBuilder

NewFormBuilder creates a new form builder.

func (*FormBuilder) AddNumberField

func (b *FormBuilder) AddNumberField(id, label string, min, max float64, required bool) *FormBuilder

AddNumberField adds a number field.

func (*FormBuilder) AddPasswordField

func (b *FormBuilder) AddPasswordField(id, label, placeholder string, required bool) *FormBuilder

AddPasswordField adds a password field.

func (*FormBuilder) AddSelectField

func (b *FormBuilder) AddSelectField(id, label string, options []string, defaultValue string, required bool) *FormBuilder

AddSelectField adds a select field.

func (*FormBuilder) AddTextField

func (b *FormBuilder) AddTextField(id, label, placeholder string, required bool) *FormBuilder

AddTextField adds a text field.

func (*FormBuilder) Build

func (b *FormBuilder) Build() UIRequest

Build finalizes the form request.

func (*FormBuilder) WithCancelLabel

func (b *FormBuilder) WithCancelLabel(label string) *FormBuilder

WithCancelLabel sets the cancel button label.

func (*FormBuilder) WithSubmitLabel

func (b *FormBuilder) WithSubmitLabel(label string) *FormBuilder

WithSubmitLabel sets the submit button label.

func (*FormBuilder) WithTitle

func (b *FormBuilder) WithTitle(title string) *FormBuilder

WithTitle sets the title for form.

type FormData

type FormData struct {
	Fields []FormField `json:"fields"`
}

FormData contains data for form UI.

type FormField

type FormField struct {
	ID          string      `json:"id"`
	Label       string      `json:"label"`
	Type        string      `json:"type"` // "text", "password", "number", "select", "checkbox"
	Required    bool        `json:"required,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	Placeholder string      `json:"placeholder,omitempty"`
	Options     []string    `json:"options,omitempty"` // For select type
	Min         float64     `json:"min,omitempty"`     // For number type
	Max         float64     `json:"max,omitempty"`     // For number type
	Pattern     string      `json:"pattern,omitempty"` // Regex validation
}

FormField represents a field in a form.

type FormModel

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

FormModel is a Bubble Tea model for form input.

func NewFormModel

func NewFormModel(req UIRequest) (*FormModel, error)

NewFormModel creates a new form input model.

func (*FormModel) Init

func (m *FormModel) Init() tea.Cmd

Init initializes the model.

func (*FormModel) Result

func (m *FormModel) Result() UIResponse

Result returns the form result.

func (*FormModel) Update

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

Update handles messages.

func (*FormModel) View

func (m *FormModel) View() string

View renders the form.

type FormStyles

type FormStyles struct {
	Title        lipgloss.Style
	Description  lipgloss.Style
	Label        lipgloss.Style
	Input        lipgloss.Style
	Error        lipgloss.Style
	Help         lipgloss.Style
	Button       lipgloss.Style
	ActiveButton lipgloss.Style
}

FormStyles contains styles for form rendering.

func DefaultFormStyles

func DefaultFormStyles() *FormStyles

DefaultFormStyles returns default styles for form.

type ListBuilder

type ListBuilder struct {
	*Builder
	// contains filtered or unexported fields
}

ListBuilder provides fluent API for building list selections.

func NewListBuilder

func NewListBuilder() *ListBuilder

NewListBuilder creates a new list builder.

func (*ListBuilder) AddItem

func (b *ListBuilder) AddItem(id, title, description string, value interface{}) *ListBuilder

AddItem adds an item to the list.

func (*ListBuilder) Build

func (b *ListBuilder) Build() UIRequest

Build finalizes the list request.

func (*ListBuilder) MultiSelect

func (b *ListBuilder) MultiSelect(enabled bool) *ListBuilder

MultiSelect enables multi-selection mode.

func (*ListBuilder) WithTitle

func (b *ListBuilder) WithTitle(title string) *ListBuilder

WithTitle sets the title for list.

type ListData

type ListData struct {
	Items   []ListItem `json:"items"`
	Default int        `json:"default,omitempty"`
}

ListData contains data for list selection UI.

type ListItem

type ListItem struct {
	ID          string      `json:"id"`
	Title       string      `json:"title"`
	Description string      `json:"description,omitempty"`
	Value       interface{} `json:"value,omitempty"`
	Selected    bool        `json:"selected,omitempty"`
}

ListItem represents an item in a list selection.

type ListModel

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

ListModel is a Bubble Tea model for list selection.

func NewListModel

func NewListModel(req UIRequest) (*ListModel, error)

NewListModel creates a new list selection model.

func (*ListModel) Init

func (m *ListModel) Init() tea.Cmd

Init initializes the model.

func (*ListModel) Result

func (m *ListModel) Result() UIResponse

Result returns the selection result.

func (*ListModel) Update

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

Update handles messages.

func (*ListModel) View

func (m *ListModel) View() string

View renders the list.

type ListStyles

type ListStyles struct {
	Title       lipgloss.Style
	Description lipgloss.Style
	Item        lipgloss.Style
	Selected    lipgloss.Style
	Cursor      lipgloss.Style
	Help        lipgloss.Style
}

ListStyles contains styles for list rendering.

func DefaultListStyles

func DefaultListStyles() *ListStyles

DefaultListStyles returns default styles for list.

type TableBuilder

type TableBuilder struct {
	*Builder
	// contains filtered or unexported fields
}

TableBuilder provides fluent API for building tables.

func NewTableBuilder

func NewTableBuilder() *TableBuilder

NewTableBuilder creates a new table builder.

func (*TableBuilder) AddColumn

func (b *TableBuilder) AddColumn(id, title string, width int, align string) *TableBuilder

AddColumn adds a column definition.

func (*TableBuilder) AddRow

func (b *TableBuilder) AddRow(id string, values map[string]string) *TableBuilder

AddRow adds a row to the table.

func (*TableBuilder) Build

func (b *TableBuilder) Build() UIRequest

Build finalizes the table request.

func (*TableBuilder) ShowHeaders

func (b *TableBuilder) ShowHeaders(show bool) *TableBuilder

ShowHeaders enables header display.

func (*TableBuilder) WithTitle

func (b *TableBuilder) WithTitle(title string) *TableBuilder

WithTitle sets the title for table.

type TableColumn

type TableColumn struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Width int    `json:"width,omitempty"`
	Align string `json:"align,omitempty"` // "left", "center", "right"
}

TableColumn represents a column in a table.

type TableData

type TableData struct {
	Columns []TableColumn `json:"columns"`
	Rows    []TableRow    `json:"rows"`
}

TableData contains data for table display.

type TableModel

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

TableModel is a Bubble Tea model for table display.

func NewTableModel

func NewTableModel(req UIRequest) (*TableModel, error)

NewTableModel creates a new table display model.

func (*TableModel) Init

func (m *TableModel) Init() tea.Cmd

Init initializes the model.

func (*TableModel) Result

func (m *TableModel) Result() UIResponse

Result returns the table interaction result.

func (*TableModel) Update

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

Update handles messages.

func (*TableModel) View

func (m *TableModel) View() string

View renders the table.

type TableRow

type TableRow struct {
	ID     string            `json:"id"`
	Values map[string]string `json:"values"`
}

TableRow represents a row in a table.

type TableStyles

type TableStyles struct {
	Title       lipgloss.Style
	Description lipgloss.Style
	Header      lipgloss.Style
	Row         lipgloss.Style
	Selected    lipgloss.Style
	Cursor      lipgloss.Style
	Border      lipgloss.Style
	Help        lipgloss.Style
}

TableStyles contains styles for table rendering.

func DefaultTableStyles

func DefaultTableStyles() *TableStyles

DefaultTableStyles returns default styles for table.

type UIOptions

type UIOptions struct {
	// Common options
	Width       int  `json:"width,omitempty"`
	Height      int  `json:"height,omitempty"`
	ShowHelp    bool `json:"show_help,omitempty"`
	AllowCancel bool `json:"allow_cancel,omitempty"`

	// List options
	MultiSelect bool `json:"multi_select,omitempty"`
	ShowIndices bool `json:"show_indices,omitempty"`

	// Form options
	SubmitLabel string `json:"submit_label,omitempty"`
	CancelLabel string `json:"cancel_label,omitempty"`

	// Table options
	ShowHeaders bool `json:"show_headers,omitempty"`
	Sortable    bool `json:"sortable,omitempty"`
	Filterable  bool `json:"filterable,omitempty"`
}

UIOptions provides display options for UI components.

type UIRequest

type UIRequest struct {
	// Common fields
	Title       string          `json:"title,omitempty"`
	Description string          `json:"description,omitempty"`
	Type        string          `json:"type"` // "list", "form", "table", "confirm"
	Data        json.RawMessage `json:"data"`
	Options     UIOptions       `json:"options,omitempty"`
}

UIRequest represents a request to display a UI component.

func QuickForm

func QuickForm(title string, fields map[string]string) UIRequest

QuickForm creates a simple form with text fields.

func QuickList

func QuickList(title string, items map[string]string) UIRequest

QuickList creates a simple list selection.

func QuickTable

func QuickTable(title string, headers []string, rows [][]string) UIRequest

QuickTable creates a simple table from data.

type UIResponse

type UIResponse struct {
	Type     string          `json:"type"`
	Selected interface{}     `json:"selected,omitempty"`
	Input    interface{}     `json:"input,omitempty"`
	Canceled bool            `json:"canceled"`
	Duration time.Duration   `json:"duration"`
	Data     json.RawMessage `json:"data,omitempty"`
}

UIResponse represents the result of a UI interaction.

func RunConfirm

func RunConfirm(req UIRequest, output io.Writer) (UIResponse, error)

RunConfirm runs a confirmation dialog and returns the result.

func RunForm

func RunForm(req UIRequest, output io.Writer) (UIResponse, error)

RunForm runs a form UI and returns the result.

func RunList

func RunList(req UIRequest, output io.Writer) (UIResponse, error)

RunList runs a list selection UI and returns the result.

func RunTable

func RunTable(req UIRequest, output io.Writer) (UIResponse, error)

RunTable runs a table UI and returns the result.

Jump to

Keyboard shortcuts

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