tui

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tui provides terminal user interface components including a fuzzy-search selector for selecting items from lists.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.ErrCanceled

ErrCancelled is returned when the user cancels the selection

Functions

func RunInputForm added in v0.2.14

func RunInputForm(fields []InputField, useColors bool) (map[string]string, error)

RunInputForm displays the form and returns collected values. Returns nil map if user cancels (Escape), or error on failure.

Types

type InputField added in v0.2.14

type InputField struct {
	Name        string // Parameter name (e.g., "id")
	Description string // Optional description for the field
	Default     string // Default value (from session)
	Value       string // Current value
	IsSecret    bool   // Whether the field should be masked (password-style input)
}

InputField represents a single input field in the form.

type InputFormModel added in v0.2.14

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

InputFormModel is a Bubbletea model for multi-field input.

func NewInputFormModel added in v0.2.14

func NewInputFormModel(fields []InputField, useColors bool) InputFormModel

NewInputFormModel creates a new input form with the given fields.

func (InputFormModel) Canceled added in v0.2.14

func (m InputFormModel) Canceled() bool

Canceled returns true if the form was canceled.

func (InputFormModel) Init added in v0.2.14

func (m InputFormModel) Init() tea.Cmd

Init initializes the model.

func (InputFormModel) Submitted added in v0.2.14

func (m InputFormModel) Submitted() bool

Submitted returns true if the form was submitted.

func (InputFormModel) Update added in v0.2.14

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

Update handles messages and updates the model.

func (InputFormModel) Values added in v0.2.14

func (m InputFormModel) Values() map[string]string

Values returns the collected values as a map. Returns nil if the form was canceled.

func (InputFormModel) View added in v0.2.14

func (m InputFormModel) View() string

View renders the input form.

type InputFormStyles added in v0.2.14

type InputFormStyles struct {
	Title        lipgloss.Style
	Label        lipgloss.Style
	LabelFocused lipgloss.Style
	Help         lipgloss.Style
	Cursor       lipgloss.Style
}

InputFormStyles holds styling configuration for the input form.

func DefaultInputFormStyles added in v0.2.14

func DefaultInputFormStyles() InputFormStyles

DefaultInputFormStyles returns the default styling for the input form.

func NoColorInputFormStyles added in v0.2.14

func NoColorInputFormStyles() InputFormStyles

NoColorInputFormStyles returns styles without colors.

type Item

type Item interface {
	// FilterValue returns the string used for fuzzy matching
	FilterValue() string
	// Title returns the main display text
	Title() string
	// Description returns secondary text (displayed dimmed)
	Description() string
	// String returns formatted string for display: [index] title  description
	String() string
}

Item interface for selectable items

func Run

func Run(items []Item, useColors bool) (Item, int, error)

Run runs the selector and returns the selected item and its original index Returns nil, -1, ErrCancelled if user cancelled, or nil, -1, error for other errors

type Model

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

Model is the Bubbletea model for the selector

func NewModel

func NewModel(items []Item, useColors bool) Model

NewModel creates a new selector model

func (Model) Cancelled

func (m Model) Cancelled() bool

Cancelled returns true if the selection was cancelled

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the model

func (Model) Selected

func (m Model) Selected() Item

Selected returns the selected item, or nil if cancelled

func (Model) SelectedIndex

func (m Model) SelectedIndex() int

SelectedIndex returns the original index of the selected item, or -1 if cancelled

func (Model) Update

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

Update handles messages and updates the model

func (Model) View

func (m Model) View() string

View renders the selector

type Styles

type Styles struct {
	Title         lipgloss.Style
	SelectedItem  lipgloss.Style
	NormalItem    lipgloss.Style
	MatchedChars  lipgloss.Style
	Cursor        lipgloss.Style
	Help          lipgloss.Style
	NoResults     lipgloss.Style
	SearchPrompt  lipgloss.Style
	MethodGET     lipgloss.Style
	MethodPOST    lipgloss.Style
	MethodPUT     lipgloss.Style
	MethodDELETE  lipgloss.Style
	MethodPATCH   lipgloss.Style
	MethodDefault lipgloss.Style
	Description   lipgloss.Style
	Index         lipgloss.Style
	SelectedIndex lipgloss.Style
}

Styles holds the styling configuration for the selector

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns the default styling for the selector

func NoColorStyles

func NoColorStyles() Styles

NoColorStyles returns styles without colors for non-color mode

Jump to

Keyboard shortcuts

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