core

package
v0.17.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
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

func (b *BaseModel) HandleCommonMsg(msg tea.Msg) (bool, tea.Cmd)

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

func (b *BaseModel) InitSpinner() tea.Cmd

InitSpinner initializes the spinner with default settings. Call this from Init() after SignalReady().

func (*BaseModel) IsDone

func (b *BaseModel) IsDone() bool

IsDone returns true if the operation is complete.

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) IsActive

func (s Status) IsActive() bool

IsActive returns true if the status indicates active work.

func (Status) IsTerminal

func (s Status) IsTerminal() bool

IsTerminal returns true if this status represents a final state (done, error, or skipped).

func (Status) String

func (s Status) String() string

String returns the string representation of the status.

Jump to

Keyboard shortcuts

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