Documentation
¶
Index ¶
- func CaptureInput() tea.Msg
- func EnterAltScreen() tea.Msg
- func ExitAltScreen() tea.Msg
- func IsInput(msg tea.Msg) bool
- func IsKeyboard(msg tea.Msg) bool
- func IsMouse(msg tea.Msg) bool
- func Key(msg tea.Msg, keys ...string) bool
- func MatchRoute(route string, placeholder string) (map[string]string, bool)
- func Mouse(ctx *Ctx, msg tea.Msg) (x, y int, ok bool)
- func MouseAt(msg tea.Msg) (x, y int, ok bool)
- func ReleaseInput() tea.Msg
- func Resolve(base, target string) string
- func SetBackgroundColor(colour color.Color) tea.Cmd
- func SetBracketedPaste(on bool) tea.Cmd
- func SetForegroundColor(colour color.Color) tea.Cmd
- func SetKeyboardEnhancements(enhancements tea.KeyboardEnhancements) tea.Cmd
- func SetMouseMode(mode tea.MouseMode) tea.Cmd
- func SetProgressBar(bar *tea.ProgressBar) tea.Cmd
- func SetReportFocus(on bool) tea.Cmd
- func SetWindowTitle(title string) tea.Cmd
- func TranslateMouse(msg tea.Msg, dx, dy int) tea.Msg
- type App
- func (a *App) Ctx() *Ctx
- func (a *App) Init() tea.Cmd
- func (a *App) InputCaptured() bool
- func (a *App) Program(options ...tea.ProgramOption) *tea.Program
- func (a *App) Route() string
- func (a *App) Run(options ...tea.ProgramOption) error
- func (a *App) Scope() *Scope
- func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (a *App) View() tea.View
- type BasicComponent
- type Component
- type Ctx
- func (c *Ctx) CursorAt(x, y int)
- func (c *Ctx) Focused() bool
- func (c *Ctx) Height() int
- func (c *Ctx) InputCaptured() bool
- func (c *Ctx) Inset(dx, dy, width, height int) *Ctx
- func (c *Ctx) Navigate(target string) tea.Cmd
- func (c *Ctx) OnDestroy(cleanup func())
- func (c *Ctx) Origin() (int, int)
- func (c *Ctx) PreviousRoute() string
- func (c *Ctx) Route() string
- func (c *Ctx) Scope() *Scope
- func (c *Ctx) SetCursor(cursor *tea.Cursor)
- func (c *Ctx) SetRoute(target string) tea.Cmd
- func (c *Ctx) Size() (int, int)
- func (c *Ctx) Width() int
- func (c *Ctx) WithFocus(focused bool) *Ctx
- func (c *Ctx) WithScope(scope *Scope) *Ctx
- type InvisibleComponent
- type Option
- type Reactified
- type ReactifiedWidget
- type RenderFunc
- type RouteChangedMsg
- type Scope
- type Widget
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureInput ¶
CaptureInput declares that something below is taking the keys — a text field in filter mode, a modal. Global key handling at the root stands down until the matching ReleaseInput. Calls nest, so they must be paired.
func EnterAltScreen ¶
EnterAltScreen puts the program in the alternate screen buffer.
func ExitAltScreen ¶
ExitAltScreen returns to the normal screen buffer.
func IsInput ¶
IsInput reports whether msg is addressed to one component rather than to all of them.
func IsKeyboard ¶
IsKeyboard reports whether msg is a key or paste event.
func Key ¶
Key reports whether msg is a press of one of keys, spelled the way tea.KeyPressMsg.String does.
func MatchRoute ¶
MatchRoute reports whether route (e.g. /teams/123/12) matches placeholder (e.g. /teams/:teamId/:playerId) and returns the params it captured.
Params follow ^:.*$, where ^ is the start of a path level and $ its end.
- The whole matched route is available under the key "$".
- Placeholders can be optional: /foo/?:/?: matches /foo, /foo/bar and /foo/bar/baz.
- A trailing placeholder can be an optional catch-all: /foo/+?: matches /foo and everything below it.
- Wildcards are allowed: /foo/:/bar.
- A repeated param name keeps the value of its last occurrence.
func Mouse ¶
Mouse reports whether msg is a mouse event inside this component's box. Containers translate as they route, so the coordinates are already box-local.
func SetBackgroundColor ¶
SetBackgroundColor sets the terminal background. Pass nil to reset it.
func SetBracketedPaste ¶
SetBracketedPaste turns bracketed paste on or off. It is on by default.
func SetForegroundColor ¶
SetForegroundColor sets the terminal foreground. Pass nil to reset it.
func SetKeyboardEnhancements ¶
func SetKeyboardEnhancements(enhancements tea.KeyboardEnhancements) tea.Cmd
SetKeyboardEnhancements asks the terminal for richer key reporting.
func SetMouseMode ¶
SetMouseMode asks the terminal for mouse reporting.
func SetProgressBar ¶
func SetProgressBar(bar *tea.ProgressBar) tea.Cmd
SetProgressBar shows a progress bar in the terminal's progress area. Pass nil to take it away.
func SetReportFocus ¶
SetReportFocus turns focus reporting on or off.
func SetWindowTitle ¶
SetWindowTitle sets the terminal window title.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App owns a running program's state. It lives here rather than in package variables, so two apps in one process never share a route. Commands go straight back to Bubbletea, which already runs them under a panic guard.
func (*App) InputCaptured ¶
InputCaptured reports whether something below has claimed the keys.
func (*App) Program ¶
func (a *App) Program(options ...tea.ProgramOption) *tea.Program
Program wraps the app in a Bubbletea program. Any quit closes the root scope first.
func (*App) Run ¶
func (a *App) Run(options ...tea.ProgramOption) error
Run builds a program and runs it.
type BasicComponent ¶
type BasicComponent struct{}
BasicComponent implements Init and Update as no-ops.
type Component ¶
type Component interface {
Init(*Ctx) tea.Cmd
Update(*Ctx, tea.Msg) tea.Cmd
// Render should be a function of the component's state: ask for terminal
// features with commands, not while drawing. The cursor is the exception,
// since it depends on the layout.
Render(*Ctx) string
}
Component is a piece of UI. Update is not guaranteed to run before the first Render, so put anything critical in Init. There is no Destroy; register cleanups with Ctx.OnDestroy so a parent cannot leak a child by forgetting to forward one.
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
Ctx is the box a component may draw into, where the app is, and the scope its cleanups belong to. A Ctx knows its origin on screen, so a cursor set through it is translated for the component and no parent does offset arithmetic.
func (*Ctx) Focused ¶
Focused reports whether this component holds the keyboard focus. Containers decide it; a component reads it to style itself and to know whether keys are meant for it.
func (*Ctx) InputCaptured ¶
InputCaptured reports whether something below has claimed the keys, so a component reading global keys knows to stand down.
func (*Ctx) Inset ¶
Inset carves a child box out of this one, clamped to what is left so a child can never start outside its parent.
func (*Ctx) OnDestroy ¶
func (c *Ctx) OnDestroy(cleanup func())
OnDestroy registers a cleanup with this Ctx's scope.
func (*Ctx) PreviousRoute ¶
PreviousRoute is where the app was before the last route change.
func (*Ctx) SetCursor ¶
SetCursor places the cursor inside this box for this frame. It stays a render concern because it depends on the layout; everything else the terminal can be asked for is a command. Pass nil to hide it.
A component without the focus is ignored, so one cursor per frame falls out of the focus rules instead of being a race between siblings.
func (*Ctx) SetRoute ¶
SetRoute moves to an absolute route when the returned command runs, so it is safe to call from any goroutine.
type InvisibleComponent ¶
type InvisibleComponent struct{}
InvisibleComponent renders nothing.
func (*InvisibleComponent) Render ¶
func (c *InvisibleComponent) Render(*Ctx) string
type Option ¶
type Option func(*App)
Option configures an App.
func WithAltScreen ¶
func WithAltScreen() Option
WithAltScreen starts in the alternate screen buffer.
func WithTerminal ¶
WithTerminal seeds terminal state before the first frame. Bubbletea renders once before running Init's commands, so asking with a command alone flashes a frame onto the primary screen.
func WithWindowTitle ¶
WithWindowTitle sets the terminal window title.
type Reactified ¶
type Reactified[TModel tea.Model] struct { BasicComponent Model TModel // contains filtered or unexported fields }
Reactified adapts a tea.Model. A bubbles widget returns its own concrete type from Update, so it never satisfies tea.Model; use ReactifyWidget for those.
func Reactify ¶
func Reactify[TModel tea.Model](model TModel) *Reactified[TModel]
Reactify wraps a tea.Model as a Component.
func (*Reactified[TModel]) Render ¶
func (c *Reactified[TModel]) Render(ctx *Ctx) string
type ReactifiedWidget ¶
type ReactifiedWidget[TWidget Widget[TWidget]] struct { BasicComponent Widget TWidget }
ReactifiedWidget adapts a bubbles widget.
func ReactifyWidget ¶
func ReactifyWidget[TWidget Widget[TWidget]](widget TWidget) *ReactifiedWidget[TWidget]
ReactifyWidget wraps a bubbles widget as a Component.
func (*ReactifiedWidget[TWidget]) Init ¶
func (c *ReactifiedWidget[TWidget]) Init(*Ctx) tea.Cmd
Only some widgets (timer, stopwatch, filepicker, progress) have an Init, which is why it is not part of Widget.
func (*ReactifiedWidget[TWidget]) Render ¶
func (c *ReactifiedWidget[TWidget]) Render(ctx *Ctx) string
A widget exposes Cursor() separately from View(), and only once its virtual cursor is off and it is focused. Reactea forces neither.
type RenderFunc ¶
RenderFunc is a stateless component: props are whatever the closure captures.
type RouteChangedMsg ¶
RouteChangedMsg is delivered to the whole tree after the route moves.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope owns the cleanups of everything mounted under it. It replaces a Destroy method on Component: a parent that mounts and unmounts children gives each a Child scope, and everything else falls back to the app's root scope, so a forgotten call cannot strand a cleanup.
func (*Scope) Child ¶
Child opens a nested scope. Closing the parent closes it too; closing the child early unmounts one thing without touching the rest.
type Widget ¶
Widget is the shape every bubbles widget has. The self-referential type parameter is what lets one adapter cover textinput, textarea, viewport, list and friends. An interface whose Update returns itself also fits: name it as the type argument, as in ReactifyWidget[huh.Model](form).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
tour
command
Command tour exercises every part of the reactea v2 API in one screen.
|
Command tour exercises every part of the reactea v2 API in one screen. |
|
Package layout splits a box among child components along one axis.
|
Package layout splits a box among child components along one axis. |
|
Package modal stacks blocking overlays on a base component.
|
Package modal stacks blocking overlays on a base component. |
|
Package router picks a child component from the app's current route.
|
Package router picks a child component from the app's current route. |