taro

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 23 Imported by: 0

README

taro

Package taro is a high level framework for defining terminal interfaces that obey cy's Screen interface. It is a fork of charmbracelet/bubbletea and borrows that library's state machine paradigm, originally inspired by the Elm framework.

I wanted bubbletea Programs to be able to write to arbitrary parts of the screen without futzing with strings. I also needed to improve on bubbletea's key/mouse event parsing (which, at any rate, has since been patched).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProgramKilled = errors.New("program was killed")

ErrProgramKilled is returned by Program.Run when the program got killed.

Functions

func GetSize added in v0.1.6

func GetSize(text string) geom.Vec2

GetSize gets the size of `text` as it would appear on the screen.

func Progress added in v1.5.0

func Progress(
	filledStyle, emptyStyle lipgloss.Style,
	text string,
	percent float64,
) string

Progress applies a lipgloss.Style to a percentage of the input text.

func Sequence

func Sequence(cmds ...tea.Cmd) tea.Cmd

Sequence runs the given commands one at a time, in order. Contrast this with Batch, which runs commands concurrently.

func Test added in v0.1.13

func Test(m Model, options ...Option) func(msgs ...interface{})

Test returns a function that passes the given messages to the taro Model `m` one at a time. All `Cmd`s that would normally be executed in separate goroutines are instead executed in the calling goroutine. This is useful exclusively in testing.

func WithDebug added in v1.9.0

func WithDebug(p *Program)

func WithExisting added in v1.9.0

func WithExisting(p *Program)

func WithKittyKeys added in v1.9.0

func WithKittyKeys(p *Program)

Types

type Cmd

type Cmd = tea.Cmd

func WaitScreens added in v0.1.5

func WaitScreens(ctx context.Context, screens ...mux.Screen) Cmd

type KeyMsg

type KeyMsg = tea.KeyMsg

type KittyKeyMsg added in v1.9.0

type KittyKeyMsg keys.Key

func KeysToMsg added in v0.1.5

func KeysToMsg(strs ...string) (msgs []KittyKeyMsg)

func (KittyKeyMsg) Tea added in v1.9.0

func (k KittyKeyMsg) Tea() (tea.KeyMsg, bool)

type Model

type Model interface {
	// Init is the first function that will be called. It returns an optional
	// initial command. To not perform an initial command return nil.
	Init() Cmd

	// Update is called when a message is received. Use it to inspect messages
	// and, in response, update the model and/or send a command.
	Update(Msg) (Model, Cmd)

	// View renders the program's UI, which consists of a full *tty.State. The
	// view is rendered after every Update.
	View(*tty.State)
}

Model contains the program's state as well as its core functions.

type MouseMsg

type MouseMsg keys.Mouse

func (MouseMsg) String

func (m MouseMsg) String() string

String returns a string representation of a mouse event.

type Msg

type Msg = events.Msg

func DetectOneMsg

func DetectOneMsg(b []byte) (msg Msg, w int)

func TranslateMouseMessage added in v0.1.6

func TranslateMouseMessage(msg Msg, dx, dy int) Msg

type Option added in v1.9.0

type Option func(p *Program)

type Program

type Program struct {
	util.Lifetime
	// contains filtered or unexported fields
}

Program is a terminal user interface.

func Existing added in v1.5.0

func Existing(ctx context.Context, model Model) *Program

func New

func New(ctx context.Context, model Model, options ...Option) *Program

func (*Program) Kill

func (p *Program) Kill()

Kill stops the program immediately and restores the former terminal state. The final render that you would normally see when quitting will be skipped. [program.Run] returns a ErrProgramKilled error.

func (*Program) Quit

func (p *Program) Quit()

Quit is a convenience function for quitting Bubble Tea programs. Use it when you need to shut down a Bubble Tea program from the outside.

If you wish to quit from within a Bubble Tea program use the Quit command.

If the program is not running this will be a no-op, so it's safe to call if the program is unstarted or has already exited.

func (*Program) Resize

func (p *Program) Resize(size geom.Size) error

func (*Program) Run

func (p *Program) Run() (Model, error)

Run initializes the program and runs its event loops, blocking until it gets terminated by either Program.Quit, Program.Kill, or its signal handler. Returns the final model.

func (*Program) Send

func (p *Program) Send(msg events.Msg)

Send sends a message to the main update function, effectively allowing messages to be injected from outside the program for interoperability purposes.

If the program hasn't started yet this will be a blocking operation. If the program has already been terminated this will be a no-op, so it's safe to send messages after the program has exited.

func (*Program) State

func (r *Program) State() *tty.State

func (*Program) Wait

func (p *Program) Wait()

Wait waits/blocks until the underlying Program finished shutting down.

func (*Program) Write

func (p *Program) Write(data []byte) (n int, err error)

type PublishMsg added in v0.1.6

type PublishMsg struct {
	Msg Msg
}

Indicates that this message should be emitted upwards.

type RawMsg added in v1.12.0

type RawMsg struct {
	Data []byte
}

MouseMsg contains information about a mouse event and are sent to a programs update function when mouse activity occurs. Note that the mouse must first be enabled in order for the mouse events to be received. RawMsg sends raw bytes directly to a terminal's underlying stream without bracketed paste wrapping or any other encoding.

type Renderer

type Renderer struct {
	*lipgloss.Renderer
	// contains filtered or unexported fields
}

Renderer makes it easy to render lipgloss strings.

func NewRenderer

func NewRenderer() *Renderer

func (*Renderer) LipglossToEmu added in v1.8.0

func (r *Renderer) LipglossToEmu(color lipgloss.Color) emu.Color

func (*Renderer) ProgressBar added in v1.10.0

func (r *Renderer) ProgressBar(
	emptyStyle lipgloss.Style,
	width int,
	leftText, rightText string,
	percent float64,
) string

ProgressBar renders a single-line progress bar with left and right text. The returned string will have a width of `width` (or less if width is <= 0). The filled portion uses inverted colors from the empty style.

func (*Renderer) RenderAt

func (r *Renderer) RenderAt(state image.Image, row, col int, value string)

RenderAt renders the given string at (row, col) in `state`.

func (*Renderer) RenderAtSize added in v1.3.0

func (r *Renderer) RenderAtSize(
	state image.Image,
	row, col int,
	rows, cols int,
	value string,
)

RenderAtSize renders the given string at (row, col) in `state` with a fixed terminal size.

func (*Renderer) RenderImage added in v0.1.6

func (r *Renderer) RenderImage(value string) image.Image

type ScreenUpdate added in v0.1.5

type ScreenUpdate struct {
	Screen mux.Screen
	Msg    Msg
	// contains filtered or unexported fields
}

func (ScreenUpdate) Wait added in v0.1.16

func (s ScreenUpdate) Wait() Cmd

type ScreenWatcher added in v0.1.6

type ScreenWatcher struct {
	util.Lifetime
	// contains filtered or unexported fields
}

func NewWatcher added in v0.1.6

func NewWatcher(ctx context.Context, screen mux.Screen) *ScreenWatcher

func (*ScreenWatcher) Wait added in v0.1.6

func (s *ScreenWatcher) Wait() Cmd

Jump to

Keyboard shortcuts

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