Documentation
¶
Overview ¶
Package core provides foundational TUI types that can be imported without cycles. This package contains BaseModel, ReadySignaler, and key constants that components need.
Index ¶
Constants ¶
const ( KeyCtrlC = "ctrl+c" KeyQuit = "q" KeyEsc = "esc" KeyEnter = "enter" KeyUp = "up" KeyDown = "down" KeyLeft = "left" KeyRight = "right" KeyTab = "tab" )
Key constants for TUI interactions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct {
Spinner spinner.Model
Done bool
Width int
Height int
// contains filtered or unexported fields
}
BaseModel provides common functionality for all TUI models. Embed this in component models to get standard lifecycle handling.
Usage:
type MyModel struct {
core.BaseModel
// ... other fields
}
func (m *MyModel) Init() tea.Cmd {
m.SignalReady()
return m.InitSpinner()
}
func (m *MyModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if handled, cmd := m.HandleCommonMsg(msg); handled {
return m, cmd
}
// ... handle other messages
}
func (*BaseModel) HandleCommonMsg ¶
HandleCommonMsg processes messages common to all models. Returns (handled bool, cmd tea.Cmd). If handled is true, the model should return the cmd and not process the message further.
Handles: - tea.KeyPressMsg: "ctrl+c" and "q" quit the program - tea.WindowSizeMsg: updates Width and Height (returns handled=false so model can also handle) - spinner.TickMsg: updates the spinner
func (*BaseModel) InitSpinner ¶
InitSpinner initializes the spinner with default settings. Call this from Init() after SignalReady().
func (*BaseModel) MarkDone ¶
func (b *BaseModel) MarkDone()
MarkDone sets the Done flag to true. Call this when the operation is complete.
func (*BaseModel) SetReadyChan ¶
func (b *BaseModel) SetReadyChan(ch chan struct{})
SetReadyChan implements ReadySignaler. This is called by the Runner before starting the program.
func (*BaseModel) SignalReady ¶
func (b *BaseModel) SignalReady()
SignalReady should be called from Init() to signal the runner that the model is ready to receive messages. This prevents race conditions where Send() is called before the event loop is running.
type ReadySignaler ¶
type ReadySignaler interface {
SetReadyChan(chan struct{})
}
ReadySignaler allows a model to signal when it's ready to receive messages. Models implementing this interface will have their SetReadyChan called before the program starts, and should close the channel in their Init() method.
type Status ¶
type Status string
Status represents the state of an operation or phase. This provides a unified status type across all TUI components.
const ( // StatusPending indicates the operation has not started. StatusPending Status = "pending" // StatusActive indicates the operation is in progress. StatusActive Status = "active" // StatusDone indicates the operation completed successfully. StatusDone Status = "done" // StatusError indicates the operation failed. StatusError Status = "error" // StatusSkipped indicates the operation was skipped. StatusSkipped Status = "skipped" // StatusWaiting indicates the operation is waiting for user input or external event. StatusWaiting Status = "waiting" )
func (Status) IsTerminal ¶
IsTerminal returns true if this status represents a final state (done, error, or skipped).