Documentation
¶
Overview ¶
Package notify provides a notification system for the grut TUI. It supports three tiers: toasts (auto-dismiss), inline (persistent), and modal (blocking) notifications.
Index ¶
- Constants
- func SafeUpdate(p panels.Panel, msg tea.Msg) (result panels.Panel, cmd tea.Cmd)
- func SafeView(p panels.Panel, w, h int) (content string)
- func ShowActionPicker(title string, actions []ActionOption) tea.Cmd
- func ShowActionPickerWithCheckbox(title, message, checkboxLabel string, actions []ActionOption) tea.Cmd
- func ShowActionPickerWithMessage(title, message string, actions []ActionOption) tea.Cmd
- func ShowConfirm(title, message string) tea.Cmd
- func ShowConfirmWithCheckbox(title, message, checkboxLabel string) tea.Cmd
- func ShowInput(title, placeholder string) tea.Cmd
- func ShowInputWithValue(title, placeholder, value string) tea.Cmd
- type ActionOption
- type Level
- type Manager
- func (m *Manager) AddInline(id, msg string, level Level)
- func (m *Manager) AddToast(msg string, level Level) tea.Cmd
- func (m *Manager) AddToastWithDuration(msg string, level Level, d time.Duration) tea.Cmd
- func (m *Manager) DismissInline(id string)
- func (m *Manager) HasModal() bool
- func (m *Manager) InlineCount() int
- func (m *Manager) ModalView(width, height int) string
- func (m *Manager) SetSize(width, height int)
- func (m *Manager) ToastCount() int
- func (m *Manager) Update(msg tea.Msg) tea.Cmd
- func (m *Manager) View(width int) string
- type ModalKind
- type ModalResultMsg
- type Notification
- type ShowModalMsg
- type ShowToastMsg
- type ToastExpiredMsg
- type ToastTickMsg
Constants ¶
const DefaultToastDuration = 3 * time.Second
DefaultToastDuration is the default auto-dismiss time for toasts.
Variables ¶
This section is empty.
Functions ¶
func SafeUpdate ¶
SafeUpdate wraps a panel's Update call in a recovery boundary. If the panel panics, the panic is caught, logged via slog, and the original (pre-panic) panel is returned along with a command that produces a ShowToastMsg with the error details.
func SafeView ¶
SafeView wraps a panel's View call in a recovery boundary. If the panel panics, the panic is caught, logged via slog, and an error placeholder is returned instead of the panel content.
func ShowActionPicker ¶
func ShowActionPicker(title string, actions []ActionOption) tea.Cmd
ShowActionPicker returns a tea.Cmd that produces a ShowModalMsg for an action picker dialog with a selectable list of actions.
func ShowActionPickerWithCheckbox ¶
func ShowActionPickerWithCheckbox(title, message, checkboxLabel string, actions []ActionOption) tea.Cmd
ShowActionPickerWithCheckbox returns a tea.Cmd that produces a ShowModalMsg for an action picker dialog with a "remember this choice" checkbox.
func ShowActionPickerWithMessage ¶
func ShowActionPickerWithMessage(title, message string, actions []ActionOption) tea.Cmd
ShowActionPickerWithMessage returns a tea.Cmd that produces a ShowModalMsg for an action picker dialog with a title, subtitle message, and selectable list of actions.
func ShowConfirm ¶
ShowConfirm returns a tea.Cmd that produces a ShowModalMsg for a yes/no confirmation dialog.
func ShowConfirmWithCheckbox ¶
ShowConfirmWithCheckbox returns a tea.Cmd that produces a ShowModalMsg for a confirmation dialog with a "remember this choice" checkbox.
func ShowInputWithValue ¶
ShowInputWithValue returns a tea.Cmd that produces a ShowModalMsg for a text input dialog pre-filled with the given value.
Types ¶
type ActionOption ¶
type ActionOption struct {
ID string // action ID (e.g., "checkout", "copy_name")
Label string // human-readable label (e.g., "checkout", "copy name")
}
ActionOption represents a selectable action in the action picker modal.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages active notifications across all three tiers: toasts (auto-dismiss), inline (persistent), and modals (blocking). It lives in the root app model and is not owned by individual panels.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new notification manager with no active notifications.
func (*Manager) AddInline ¶
AddInline adds a persistent inline notification identified by the given id. If an inline notification with the same id already exists, it is replaced.
func (*Manager) AddToast ¶
AddToast adds an auto-dismissing toast notification with the default duration (3 seconds). The toast will be removed automatically after the duration elapses.
func (*Manager) AddToastWithDuration ¶
AddToastWithDuration adds an auto-dismissing toast notification with a custom duration.
func (*Manager) DismissInline ¶
DismissInline removes a persistent inline notification by id.
func (*Manager) InlineCount ¶
InlineCount returns the number of active inline notifications.
func (*Manager) ModalView ¶
ModalView renders the modal overlay if one is active. Returns empty string if no modal is displayed. The caller should render this on top of the main content.
func (*Manager) SetSize ¶
SetSize stores the terminal dimensions so mouse clicks can be mapped to modal-relative coordinates. The caller (app model) must call this whenever a WindowSizeMsg is received.
func (*Manager) ToastCount ¶
ToastCount returns the number of active toasts.
type ModalKind ¶
type ModalKind int
ModalKind distinguishes between confirmation and input modals.
const ( // ModalConfirm displays a yes/no confirmation dialog. ModalConfirm ModalKind = iota // ModalInput displays a text input dialog. ModalInput // ModalConfirmWithCheckbox displays a yes/no confirmation dialog with // a "remember this choice" checkbox. ModalConfirmWithCheckbox // ModalActionPicker displays a selectable list of actions. ModalActionPicker // ModalActionPickerWithCheckbox displays a selectable list of actions // with a "remember this choice" checkbox. ModalActionPickerWithCheckbox )
type ModalResultMsg ¶
ModalResultMsg is sent when a modal dialog is dismissed by the user. Accept is true if the user confirmed, false if they cancelled. Value holds the text input value for input modals. Remember is true when the checkbox was checked (ConfirmWithCheckbox only); it is always false when Accept is false.
type Notification ¶
Notification holds the data for a single notification.
type ShowModalMsg ¶
type ShowModalMsg struct {
Title string
Message string
Placeholder string // used only for input modals
Value string // initial value for input modals (pre-fill)
CheckboxLabel string // label for the checkbox (ConfirmWithCheckbox only)
Actions []ActionOption // list of actions (ModalActionPicker only)
Kind ModalKind // confirm, input, confirmWithCheckbox, or actionPicker
}
ShowModalMsg is a command message that triggers a modal dialog. The root model intercepts this and routes it to the notification manager.
type ShowToastMsg ¶
type ShowToastMsg struct {
Message string
Level Level
Duration time.Duration // 0 means use default (3s)
}
ShowToastMsg is a command message that any panel can produce to trigger a toast notification. The root model intercepts this and routes it to the notification manager.
type ToastExpiredMsg ¶
type ToastExpiredMsg struct {
// ID uniquely identifies the toast that expired.
ID int64
}
ToastExpiredMsg indicates that a specific toast has expired and should be removed from the display.
type ToastTickMsg ¶
ToastTickMsg is sent on a regular interval to drive auto-dismiss timing for active toasts.