tui

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PerformAction

func PerformAction[T interface{}](action *Action[T], f ActionFunction[T]) tea.Cmd

Wrapper that makes your life easier when performing an action You can also use the oldschool method of creating a function that returns a tea.Cmd, and use tui.NewResult() with that

Types

type Action

type Action[T interface{}] struct {
	Name     string
	Result   bool
	Error    error
	Started  bool
	Finished bool
	Attempt  uint // allows you to ignore results from previous attempts
	Data     *T
}

This is an action that can be performed by a page

func NewAction

func NewAction[T interface{}](name string) Action[T]

func (Action[T]) HasData

func (a Action[T]) HasData() bool

Can be used for optimistic updates, where you want to use the previous data while the new data is loading

func (Action[T]) IsDone

func (a Action[T]) IsDone() bool

func (Action[T]) IsError

func (a Action[T]) IsError() bool

func (Action[T]) IsLoading

func (a Action[T]) IsLoading() bool

func (Action[T]) IsSuccess

func (a Action[T]) IsSuccess() bool

func (*Action[T]) ProcessInit

func (action *Action[T]) ProcessInit(a ActionInit[T])

Check if an init matches an action and if so, start the action

func (*Action[t]) ProcessResult

func (action *Action[t]) ProcessResult(res ActionResult[t])

Checks if action matches result, and then updates the action with the result

func (*Action[T]) Reset

func (a *Action[T]) Reset()

func (*Action[T]) ResetTea

func (a *Action[T]) ResetTea() tea.Cmd

func (*Action[T]) Restart

func (a *Action[T]) Restart()

func (*Action[T]) Start

func (a *Action[T]) Start()

func (*Action[T]) StartTea

func (a *Action[T]) StartTea() tea.Cmd

type ActionFunction

type ActionFunction[T interface{}] func() (*T, error)

type ActionInit

type ActionInit[T interface{}] struct {
	Name string
}

type ActionResult

type ActionResult[T interface{}] struct {
	Name       string
	Result     bool
	Error      error
	ForAttempt uint // allows you to ignore results from previous attempts
	Data       *T
}

This is a message returned after an action is performed it describes the action and the data that was returned

func NewResult

func NewResult[T interface{}](a Action[T], success bool, err error, data *T, attempt uint) ActionResult[T]

Generate a new ActionResult from an Action

func (ActionResult[T]) IsFor

func (a ActionResult[T]) IsFor(action *Action[T]) bool

Check if a given result is for a specific action and attempt

type Actions

type Actions []*Action[any]

A collection of Actions that can be used by a model

func (Actions) ProcessResults

func (a Actions) ProcessResults(res ActionResult[any])

ProcessResult takes an ActionResult and updates the Actions where the name matches

Jump to

Keyboard shortcuts

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