tui

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package tui provides UI elements for the CLI.

Package tui provides UI elements for the CLI.

Package tui provides UI elements for the CLI.

Package tui provides UI elements for the CLI.

Package tui provides UI elements for the CLI.

Package tui provides UI elements for the CLI.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserInterrupted = errors.New("user interrupted")
)

Functions

This section is empty.

Types

type Confirm

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

Confirm represents a confirm (y/N) input element.

func NewConfirm

func NewConfirm(ctx context.Context, message string) Confirm

NewConfirm creates a new confirm input element. It asks user the question/message and wait for the confirmation (y/N).

func (Confirm) Init

func (m Confirm) Init() tea.Cmd

Init initializes the text confirm element. Implements bubbletea.Model interface.

func (Confirm) Run

func (m Confirm) Run() (bool, error)

Run runs the confirm element.

func (Confirm) Update

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

Update updates the text confirm element. Implements bubbletea.Model interface.

func (Confirm) View

func (m Confirm) View() string

View renders the confirm element view. Implements bubbletea.Model interface.

type Input

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

Input represents a text input element.

func NewInput

func NewInput(ctx context.Context, message string, opts ...InputOption) Input

NewInput creates a new text input element.

func (Input) Init

func (m Input) Init() tea.Cmd

Init initializes the text input element. Implements bubbletea.Model interface.

func (Input) Run

func (m Input) Run() (string, error)

Run runs the text input element.

func (Input) Update

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

Update updates the text input element. Implements bubbletea.Model interface.

func (Input) View

func (m Input) View() string

View renders the input element view. Implements bubbletea.Model interface.

type InputOption

type InputOption func(m *Input)

InputOption is used to set options when initializing Input. Input can accept a variable number of options.

Example usage:

p := NewInput(ctx, WithValidation(validationFunc), WithHint(hintMessage))

func WithInputDefaultValue

func WithInputDefaultValue(defaultValue string) InputOption

WithInputDefaultValue lets you specify a default value that will be shown in the dialog when the user is prompted for input.

func WithInputHint

func WithInputHint(hint string) InputOption

WithInputHint lets you specify a hint message that will be shown in the dialog when the user is prompted for input.

func WithInputValidation

func WithInputValidation(validateFunc ValidateInputFunc) InputOption

WithInputValidation lets you specify a validate function that will be used to validate user's input.

type InputPassword

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

InputPassword represents a password input element.

func NewInputPassword

func NewInputPassword(ctx context.Context, message string, opts ...InputPasswordOption) InputPassword

NewInputPassword creates a new password input element.

func (InputPassword) Init

func (m InputPassword) Init() tea.Cmd

Init initializes the password input element. Implements bubbletea.Model interface.

func (InputPassword) Run

func (m InputPassword) Run() (string, error)

Run runs the password input element.

func (InputPassword) Update

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

Update updates the password input element. Implements bubbletea.Model interface.

func (InputPassword) View

func (m InputPassword) View() string

View renders the password element view. Implements bubbletea.Model interface.

type InputPasswordOption

type InputPasswordOption func(m *InputPassword)

InputPasswordOption is used to set options when initializing InputPassword. InputPassword can accept a variable number of options.

Example usage:

p := NewInputPassword(ctx, WithValidation(validationFunc), WithHint(hintMessage))

func WithPasswordHint

func WithPasswordHint(hint string) InputPasswordOption

WithPasswordHint lets you specify a hint message that will be shown in the dialog when the user is prompted for input.

func WithPasswordValidation

func WithPasswordValidation(validateFunc ValidateInputFunc) InputPasswordOption

WithPasswordValidation lets you specify a validate function that will be used to validate user's input.

type MultiSelect

type MultiSelect struct {
	Message string              // message to display
	Choices []MultiSelectOption // possible options user may choose from
	// contains filtered or unexported fields
}

MultiSelect represents a multi-select list.

func NewMultiSelect

func NewMultiSelect(ctx context.Context, message string, choices []MultiSelectOption) MultiSelect

NewMultiSelect creates a new multi-select list.

func (MultiSelect) Init

func (m MultiSelect) Init() tea.Cmd

Init initializes the multi-select list. Implements bubbletea.Model interface.

func (MultiSelect) Run

func (m MultiSelect) Run() ([]MultiSelectOption, error)

Run starts the multi-select list. It returns the selected options and error.

func (MultiSelect) Update

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

Update updates the multi-select list. Implements bubbletea.Model interface.

func (MultiSelect) View

func (m MultiSelect) View() string

View renders the multi-select list. It returns a string representation of the UI. Implements bubbletea.Model interface.

type MultiSelectOption

type MultiSelectOption struct {
	Text     string
	Selected bool
}

MultiSelectOption represents an option in the multi-select list.

type Spinner

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

Spinner represents action with spinner element.

func NewSpinner

func NewSpinner(ctx context.Context, l *zap.SugaredLogger, steps []Step, opts ...SpinnerOption) Spinner

NewSpinner creates a new spinner element.

func (Spinner) Init

func (m Spinner) Init() tea.Cmd

func (Spinner) Run

func (m Spinner) Run() error

Run starts the spinner element. It returns the selected options and error.

func (Spinner) Update

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

Update updates the spinner element. Implements bubbletea.Model interface.

func (Spinner) View

func (m Spinner) View() string

View renders the spinner element. It returns a string representation of the UI. Implements bubbletea.Model interface.

type SpinnerOption

type SpinnerOption func(m *Spinner)

SpinnerOption is used to set options when initializing Spinner. Spinner can accept a variable number of options.

Example usage:

p := NewSpinner(ctx, WithPretty(bool))

func WithSpinnerPrettyPrint

func WithSpinnerPrettyPrint(prettyPrint bool) SpinnerOption

WithSpinnerPrettyPrint lets you specify pretty print for the spinner. It will print the spinner in a pretty way. In case the spinner is not pretty, it will print the spinner in a verbose way.

type Step

type Step struct {
	// Desc is a human-readable description of the step.
	Desc string
	// F is the function that will be called to execute the step.
	F func(ctx context.Context) error
}

Step provides a way to run a function with a pretty loading spinner animation.

type ValidateInputFunc

type ValidateInputFunc func(string) error

ValidateInputFunc is a function that returns an error if the input is invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳