App Structure¶
The Component Interface¶
Every blit widget implements Component:
type Component interface {
Init() tea.Cmd
Update(msg tea.Msg, ctx Context) (Component, tea.Cmd)
View() string
KeyBindings() []KeyBind
SetSize(w, h int)
Focused() bool
SetFocused(bool)
}
Components that support theming also implement Themed:
The App calls SetTheme on all registered components automatically when the theme changes.
Key Dispatch Order¶
When a key arrives the App dispatches it in this order:
- Overlay stack (e.g. Help, ConfigEditor, Picker)
- Built-in globals:
qquit,tabcycle focus,?help - Pane toggle key (DualPane)
- Overlay trigger keys registered with
WithOverlay - App-level keybindings registered with
WithKeyBind - Focused component's
Update
Return blit.Consumed() from Update to stop further dispatch.
Slots¶
The App organises components into named slots:
| Slot | Description |
|---|---|
SlotMain |
Primary content pane |
SlotSidebar |
Side panel (DualPane only) |
SlotFooter |
StatusBar |
WithComponent fills SlotMain. WithLayout maps DualPane.Main → SlotMain and DualPane.Side → SlotSidebar.
Registering Keybindings¶
blit.WithKeyBind(blit.KeyBind{
Key: "r",
Label: "Refresh",
Group: "DATA",
Handler: func() {
table.SetRows(fetchRows())
},
})
All registered bindings appear in the auto-generated Help overlay.
Pushing Data from Goroutines¶
app := blit.NewApp(...)
go func() {
for data := range stream {
app.Send(MyDataMsg{data})
}
}()
app.Run()
Unknown message types are forwarded to all components via Update.