boba

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 5 Imported by: 0

README

wip framework for creatinng multi model applications with bubbletea

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeState

func ChangeState(name string) tea.Cmd

Types

type App

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

func NewApp

func NewApp() *App

func (*App) Add

func (a *App) Add(name string, m tea.Model)

func (*App) Get

func (a *App) Get(name string) tea.Model

func (*App) Init

func (a *App) Init() tea.Cmd

func (*App) Register added in v0.0.3

func (a *App) Register(name string, m tea.Model)

func (*App) SetDelegate

func (a *App) SetDelegate(f UpdateFunc)

SetDelegate sets the message handler to be run before messages are passed to the focused model. This function can be used for managing your own key bindings and state handling.

If the function returns a nil tea.Cmd, then will continue and pass the message through to the currently focused model.

func (*App) SetFocus

func (a *App) SetFocus(name string)

SetFocus sets the model which will become focused and receive messages this method updates the application directly, if you would like to change focus via the MessageStateChange tea.Msg, you may use the ChangeState tea.Cmd

func (*App) SetInit

func (a *App) SetInit(f func() tea.Cmd)

SetInit sets the function to be called on initialization if no model is in focus

func (*App) Update

func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles tea.Msgs to perform updates to application model. Messages are inspected and handled in the following manner.

1. If the msg is an exit key press (crtl-c) boba exits by invoking tea.Quit 2. If the msg is a boba.MessageStateChange, then the application's focus is changed to the reference model and no tea.Cmd is returned 3. The message is then passed to the user defined delegate function to perform custom message handling, and returns the resulting tea.Cmd if not nil 4. Otherwise, the message is passed onto the currently focused model

func (*App) View

func (a *App) View() string

View returns the view to be rendered by calling the currently focused model's View() function.

type Box added in v0.0.3

type Box struct {

	// Percentage of Window height
	SizeX float64
	// Percentage of Window width
	SizeY float64
	// contains filtered or unexported fields
}

func NewBox added in v0.0.3

func NewBox(orientation string, x, y int) *Box

func (*Box) AddNode added in v0.0.3

func (m *Box) AddNode(n tea.Model, w, h int)

AddNode adds a new node with h and w percent of parent height and width

func (*Box) AddNodeWithStyle added in v0.0.3

func (m *Box) AddNodeWithStyle(n tea.Model, h, w int, style lipgloss.Style)

func (*Box) Init added in v0.0.3

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

func (*Box) Update added in v0.0.3

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

func (*Box) View added in v0.0.3

func (m *Box) View() string

type BoxNode added in v0.0.3

type BoxNode struct {
	tea.Model
	// Height represents the percent of node's parent height to fill
	SizeX float64
	// Width represents the percent of node's parent width to fill
	SizeY float64
	// contains filtered or unexported fields
}

func (*BoxNode) Init added in v0.0.3

func (n *BoxNode) Init() tea.Cmd

func (*BoxNode) Update added in v0.0.3

func (n *BoxNode) Update(msg tea.Msg) (*BoxNode, tea.Cmd)

type Input

type Input struct {
	textinput.Model
	// contains filtered or unexported fields
}

Input is a wrapper around the bubbles textinput component It exposes the ability to define a function tio be called on input submission

func NewInput

func NewInput() *Input

NewInput returns a new Input model

func (*Input) Init

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

func (*Input) SetSubmitHandler

func (m *Input) SetSubmitHandler(f func(val string) tea.Cmd)

SetSubmitHandler sets the function to be called when the user input is submitted with Enter

func (*Input) Update

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

Update calls the submit function if Enter was pressed and calls the SubmitHandler, otherwise the message is passed on to the undnerlying bubbles textinput

func (*Input) View

func (m *Input) View() string

type List

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

List is a model that displays a list of items that can be navigated and selected. The only requirement for list items are that they satisfy the Viewer interface

func NewList

func NewList() *List

NewList returns a new List model

func (*List) Add

func (m *List) Add(item interface{})

Add adds a generic item to the list which will be rendered with fmt.Sprint

func (*List) AddItem

func (m *List) AddItem(item Viewer)

AddItem adds a new item to the list

func (*List) Clear

func (m *List) Clear()

Clear removes all items from the List

func (*List) CurrentItem

func (m *List) CurrentItem() Viewer

CurrentItem returns the item at the location of the cursor

func (*List) Init

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

func (*List) SetSelectedFunc

func (m *List) SetSelectedFunc(f func(tea.Msg) tea.Cmd)

SetSelectedFunc sets the function to be called when an item is selected. It receives the selected item as a tea.Msg and must return a tea.Cmd

func (*List) Update

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

Update handles messages for moving the cursor and selecting an item

func (*List) View

func (m *List) View() string

type MessageStateChange

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

type UpdateFunc

type UpdateFunc func(tea.Msg) (tea.Model, tea.Cmd)

type Viewer

type Viewer interface {
	View() string
}

Viewer implements the View() method of a tea.Model

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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