tea

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 6 Imported by: 2

README

Tea

Tea provides an Elm inspired functional framework for interactive command-line programs. Works great for inline and full-screen interactivity.

Examples

See the examples directory.


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

And my GitHub sponsors:

Documentation

Overview

Package tea provides an Elm inspired functional framework for interactive command-line programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd func(context.Context) Msg

Cmd is a function used to perform an action, when complete you may return a message, error, or nil.

For example a comand which removes a user from a database might return a struct UserRemoved with its ID so that Update() can remove it before rendering.

Errors are special cased, so you may return an error in place of a message, this will cause the program to exit and the error will be printed. If you wish to handle errors in a different way, you should return a message containing the error and update your model accordingly.

Returning nil is a no-op.

func Batch

func Batch(cmds ...Cmd) Cmd

Batch performs many commands concurrently, with no order guarantees.

type Init

type Init func(context.Context) (Model, Cmd)

Init is a function which is invoked when starting your program, returning the initial model and optional command.

type Model

type Model interface{}

Model is the model which defines all or a subset of your program state.

type Msg

type Msg interface{}

Msg is passed to your program's Update() function, representing an action which was performed, for example a ItemRemoved msg might be a struct containing the ID of the item removed.

func Quit

func Quit(ctx context.Context) Msg

Quit is a message which exits the program.

For example:

return m, tea.Quit

type Program

type Program struct {
	// Init function.
	Init

	// Update function.
	Update

	// View function.
	View
	// contains filtered or unexported fields
}

Program is a terminal application comprised init, update, and view functions.

func NewProgram

func NewProgram(init Init, update Update, view View) *Program

NewProgram returns a new program.

func (*Program) Start

func (p *Program) Start(ctx context.Context) error

Start the program.

type Update

type Update func(context.Context, Msg, Model) (Model, Cmd)

Update is a function which is invoked for every message, allowing you to return a new, updated model and optional command.

type View

type View func(context.Context, Model) string

View is a function used to render the program's model before it is written to the terminal.

Directories

Path Synopsis
examples
Package input provides a text input.
Package input provides a text input.
Package option provides an option list with a single selectable value.
Package option provides an option list with a single selectable value.
Package options provides an options list with many selectable values.
Package options provides an options list with many selectable values.
Package progress provides a progress bar.
Package progress provides a progress bar.
Package shortcut provides a shortcut keys.
Package shortcut provides a shortcut keys.
Package spinner provides a frame-based textual spinner.
Package spinner provides a frame-based textual spinner.
Package steps provides a wizard style step progress bar.
Package steps provides a wizard style step progress bar.
Package viewport provides a scrollable view into content.
Package viewport provides a scrollable view into content.

Jump to

Keyboard shortcuts

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