bubbletea

package
v0.0.0-...-8848863 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBaseStyle

func NewBaseStyle() lipgloss.Style

NewBaseStyle returns the default lipgloss base style.

Types

type BubbleTea

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

BubbleTea represents the CLI component that wraps the `bubbletea` library.

func New

func New(p *Params) *BubbleTea

New returns a new BubbleTea struct instance.

func (*BubbleTea) AppendError

func (b *BubbleTea) AppendError(err error)

`AppendError` appends the given error to the `BubbleTea` component slice of errors.

func (BubbleTea) BroadcastResult

func (b BubbleTea) BroadcastResult() error

`BroadcastResult` broadcasts the results to the results callback.

func (BubbleTea) Error

func (b BubbleTea) Error() error

`Error` returns the current `BubbleTea` error.

func (BubbleTea) Init

func (b BubbleTea) Init() tea.Cmd

Init is the `BubbleTea` method required for implementing the `Model` interface.

func (BubbleTea) NextModel

func (b BubbleTea) NextModel() Model

NextModel returns the next model, ordered by the order field.

func (BubbleTea) Result

func (b BubbleTea) Result() (*BubbleTeaResult, error)

`Result` returns the `BubbleTea` component result.

func (*BubbleTea) ResultCallback

func (b *BubbleTea) ResultCallback(fn func(result *BubbleTeaResult) error) error

`ResultCallback` sets the given function as a `BubbleTea` component resultCallback field.

func (BubbleTea) Run

Run runs the `BubbleTea` component and returns its result.

func (BubbleTea) Update

func (b BubbleTea) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update is the `BubbleTea` method required for implementing the `Model` interface. Returns the `BubbleTea` struct and the next tea command(In case of `nil`, it indicates that the bubbletea program continues to work).

func (*BubbleTea) UpdateModel

func (b *BubbleTea) UpdateModel(model Model) error

UpdateModel updates `models` uses given model, the update is done by type.

func (BubbleTea) View

func (b BubbleTea) View() string

View is the `BubbleTea` method required for implementing the `Model` interface.

type BubbleTeaResult

type BubbleTeaResult struct {
	// `ChoicesModelResult` is the result of the `ChoicesModel` component.
	ChoicesModelResult *ChoicesModelResult

	// `TableModelResult` is the result of the `TableModel` component.
	TableModelResult *TableModelResult
}

`BubbleTeaResult` represents the `BubbleTea` component run result.

type ChoicesModel

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

ChoicesModel represents the CLI component that wraps the `bubbletea` library.

func NewChoicesModel

func NewChoicesModel(p *ChoicesModelParams) *ChoicesModel

NewChoicesModel returns a pointer for the `ChoicesModel`.

func (ChoicesModel) Init

func (b ChoicesModel) Init() tea.Cmd

Init is the `BubbleTea` method required for implementing the `Model` interface.

func (*ChoicesModel) Order

func (b *ChoicesModel) Order() uint

func (ChoicesModel) Result

func (b ChoicesModel) Result() any

`Result` returns the `ChoicesModel` component result.

func (*ChoicesModel) Update

func (b *ChoicesModel) Update(msg tea.Msg) (Model, tea.Cmd)

Update is the `BubbleTea` method required for implementing the `Model` interface.

func (ChoicesModel) View

func (b ChoicesModel) View() string

View is the `BubbleTea` method required for implementing the `Model` interface.

func (*ChoicesModel) WithBaseStyle

func (b *ChoicesModel) WithBaseStyle(baseStyle lipgloss.Style)

type ChoicesModelParams

type ChoicesModelParams struct {
	// Choice is the current CLI choice.
	Choice string

	// Choices is the slice of options available.
	Choices []string

	// Cursor is the reference of the current CLI choice.
	Cursor int

	// UI is the user interface parameters.
	UI ChoicesModelUIParams

	// BaseStyle is the base styling parameter of the BubbleTea component.
	BaseStyle lipgloss.Style

	// Order is the order parameter,
	Order uint
}

ChoicesModelParams represents the parameters struct for the `NewChoicesModel` function.

type ChoicesModelResult

type ChoicesModelResult struct {
	// Choice is the option chosen.
	Choice string
}

ChoicesModelResult represents the result of the run method.

type ChoicesModelUI

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

ChoicesModelUI represents the UI struct for the `ChoicesModel` component.

type ChoicesModelUIParams

type ChoicesModelUIParams struct {
	// Header is the UI header text.
	Header string
}

ChoicesModelUIParams represents the UI parameters for the `NewChoicesModel` function parameters.

type Model

type Model interface {
	// Init initializes the model and returns the next tea command.
	Init() tea.Cmd

	// Update updates the model and returns the same model and the next tea command.
	Update(msg tea.Msg) (Model, tea.Cmd)

	// View returns the model view representation.
	View() string

	// Result returns the model result.
	Result() any

	// WithBaseStyle updates the model to use the given base style.
	WithBaseStyle(baseStyle lipgloss.Style)

	// Order returns the order of the model.
	Order() uint
}

Model represents the component that wraps the `bubbletea` Model interface.

type Models

type Models []Model

Models are the slice of Model interfaces.

func (Models) First

func (m Models) First() Model

`First` returns the first model of the `Models` slice.

type Params

type Params struct {
	// Models are the models parameters for the `BubbleTea` component.
	Models Models

	// BaseStyle is the base styling parameter of the BubbleTea component.
	BaseStyle lipgloss.Style
}

Params represents the parameters for the `NewBubbleTea` function.

type RunParams

type RunParams struct {
	// ResultCallback is the result callback Run parameter.
	ResultCallback func(result *BubbleTeaResult) error
}

RunParams represents the Run parameters.

type TableHeader

type TableHeader struct {
	// Title is the title of the table header.
	Title string

	// Width is the styling width of the table header.
	Width uint
}

TableHeader represents the table header.

type TableModel

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

`TableModel` represents the component that implements the `Model` interface.

func NewTableModel

func NewTableModel(p *TableModelParams) *TableModel

`NewTableModel` returns a pointer to a `TableModel`.

func (TableModel) Init

func (tm TableModel) Init() tea.Cmd

`Init` is the `TableModel` method required for implementing the `Model` interface. Initializes the `TableModel` component and returns a `bubbletea` command.

func (*TableModel) Order

func (tm *TableModel) Order() uint

func (TableModel) Result

func (tm TableModel) Result() any

`Result` returns the `TableModel` component result.

func (*TableModel) Update

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

`Update` is the `TableModel` method required for implementing the `Model` interface. Updates the `TableModel` component, handles the given message updating the internal state. Returns the current `TableModel` and the resolved command. TODO(@chris-ramon): Implement the `tea.Msg` handlers.

func (TableModel) View

func (tm TableModel) View() string

`View` is the `TableModel` method required for implementing the `Model` interface. View renders the `TableModel` using the base style and returns the results.

func (*TableModel) WithBaseStyle

func (tm *TableModel) WithBaseStyle(baseStyle lipgloss.Style)

`WithBaseStyle` updates the `TableModel` component to use the given base style.

type TableModelParams

type TableModelParams struct {
	// BaseStyle is the base styling parameter.
	BaseStyle lipgloss.Style

	// Order is the order parameter.
	Order uint

	// Headers are the slice of table headers.
	Headers []TableHeader

	// Rows are the slice of table rows.
	Rows [][]string
}

`TableModelParams` represents the parameters component for the `NewTableModel` function.

type TableModelResult

type TableModelResult struct {
}

`TableModelResult` represents the `TableModel` run method result.

Jump to

Keyboard shortcuts

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