toast

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Info colors (blue)
	InfoBorderColor     = "63"  // Blue
	InfoBackgroundColor = "235" // Dark gray
	InfoTextColor       = "255" // White

	// Success colors (green)
	SuccessBorderColor     = "10"  // Green
	SuccessBackgroundColor = "235" // Dark gray
	SuccessTextColor       = "255" // White

	// Warning colors (yellow/orange)
	WarningBorderColor     = "11"  // Yellow
	WarningBackgroundColor = "235" // Dark gray
	WarningTextColor       = "255" // White

	// Error colors (red)
	ErrorBorderColor     = "9"   // Red
	ErrorBackgroundColor = "235" // Dark gray
	ErrorTextColor       = "255" // White

	// Loading colors (purple/magenta)
	LoadingBorderColor     = "13"  // Magenta
	LoadingBackgroundColor = "235" // Dark gray
	LoadingTextColor       = "255" // White
)

Color constants for toast types

Variables

View Source
var AlternativeSpinnerFrames = []string{
	"◐", "◓", "◑", "◒",
}

AlternativeSpinnerFrames provides an alternative spinner style

View Source
var DotsSpinnerFrames = []string{
	"⠋", "⠙", "⠚", "⠞", "⠖", "⠦", "⠴", "⠲", "⠳", "⠓",
}

DotsSpinnerFrames provides a dots-based spinner

View Source
var SpinnerFrames = []string{
	"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏",
}

SpinnerFrames contains the animation frames for loading spinners

View Source
var StylePresets = map[string]ToastStylePreset{
	"default": {
		Name:            "Default",
		BorderStyle:     lipgloss.RoundedBorder(),
		BorderColor:     "63",
		BackgroundColor: "235",
		TextColor:       "255",
	},
	"minimal": {
		Name:            "Minimal",
		BorderStyle:     lipgloss.NormalBorder(),
		BorderColor:     "241",
		BackgroundColor: "235",
		TextColor:       "255",
	},
	"bold": {
		Name:            "Bold",
		BorderStyle:     lipgloss.ThickBorder(),
		BorderColor:     "255",
		BackgroundColor: "235",
		TextColor:       "255",
	},
	"double": {
		Name:            "Double",
		BorderStyle:     lipgloss.DoubleBorder(),
		BorderColor:     "63",
		BackgroundColor: "235",
		TextColor:       "255",
	},
}

StylePresets contains various toast style presets

View Source
var ToastIcons = map[ToastType]string{
	ToastInfo:    "ℹ",
	ToastSuccess: "✓",
	ToastWarning: "⚠",
	ToastError:   "✗",
	ToastLoading: "⟳",
}

ToastIcons maps toast types to their default icons

Functions

func ApplyPreset

func ApplyPreset(style lipgloss.Style, presetName string) lipgloss.Style

ApplyPreset applies a style preset to a toast style

func CalculateMaxToasts

func CalculateMaxToasts(screenHeight int) int

CalculateMaxToasts calculates the maximum number of toasts based on screen height

func CalculateToastWidth

func CalculateToastWidth(screenWidth int) int

CalculateToastWidth calculates the appropriate toast width based on screen size

func CriticalError

func CriticalError(message string) tea.Cmd

CriticalError shows a persistent error that must be dismissed manually

func DeleteNotification

func DeleteNotification(itemName string, undoCmd tea.Cmd) tea.Cmd

DeleteNotification shows a delete confirmation with undo option

func DismissAllToasts

func DismissAllToasts() tea.Cmd

DismissAllToasts creates a command to dismiss all toasts

func DismissToast

func DismissToast(id string) tea.Cmd

DismissToast creates a command to dismiss a specific toast

func GetActionStyle

func GetActionStyle() lipgloss.Style

GetActionStyle returns the style for action buttons

func GetDefaultIcon

func GetDefaultIcon(toastType ToastType) string

GetDefaultIcon returns the default icon for a toast type

func GetDismissStyle

func GetDismissStyle() lipgloss.Style

GetDismissStyle returns the style for the dismiss button

func GetIconStyle

func GetIconStyle(toastType ToastType) lipgloss.Style

GetIconStyle returns the style for toast icons

func GetSpinnerFrame

func GetSpinnerFrame(progress float64, style string) string

GetSpinnerFrame returns the appropriate spinner frame for the given progress

func GetTitleStyle

func GetTitleStyle(toastType ToastType) lipgloss.Style

GetTitleStyle returns the style for toast titles

func GetToastStyle

func GetToastStyle(toastType ToastType, width int) lipgloss.Style

GetToastStyle returns themed style for toast type

func LongWarning

func LongWarning(message string) tea.Cmd

LongWarning shows a warning that stays for 7 seconds

func NetworkErrorNotification

func NetworkErrorNotification(retryCmd tea.Cmd) tea.Cmd

NetworkErrorNotification shows a network error toast

func QuickInfo

func QuickInfo(message string) tea.Cmd

QuickInfo shows a quick info message (2 seconds)

func QuickSuccess

func QuickSuccess(message string) tea.Cmd

QuickSuccess shows a quick success message (2 seconds)

func SaveNotification

func SaveNotification(filename string, undoCmd tea.Cmd) tea.Cmd

SaveNotification shows a save confirmation with undo option

func ShowCustomToast

func ShowCustomToast(config ToastConfig) tea.Cmd

ShowCustomToast creates a command to show a custom toast with full configuration

func ShowError

func ShowError(message string) tea.Cmd

ShowError creates a command to show an error toast

func ShowErrorWithTitle

func ShowErrorWithTitle(title, message string) tea.Cmd

ShowErrorWithTitle creates a command to show an error toast with a title

func ShowInfo

func ShowInfo(message string) tea.Cmd

ShowInfo creates a command to show an info toast

func ShowInfoWithTitle

func ShowInfoWithTitle(title, message string) tea.Cmd

ShowInfoWithTitle creates a command to show an info toast with a title

func ShowLoading

func ShowLoading(message string) tea.Cmd

ShowLoading creates a command to show a loading toast

func ShowLoadingWithTitle

func ShowLoadingWithTitle(title, message string) tea.Cmd

ShowLoadingWithTitle creates a command to show a loading toast with a title

func ShowPersistentToast

func ShowPersistentToast(toastType ToastType, message string) tea.Cmd

ShowPersistentToast creates a toast that requires manual dismissal

func ShowProgressToast

func ShowProgressToast(message string) tea.Cmd

ShowProgressToast creates a loading toast for tracking progress

func ShowSuccess

func ShowSuccess(message string) tea.Cmd

ShowSuccess creates a command to show a success toast

func ShowSuccessWithTitle

func ShowSuccessWithTitle(title, message string) tea.Cmd

ShowSuccessWithTitle creates a command to show a success toast with a title

func ShowTemporaryToast

func ShowTemporaryToast(toastType ToastType, message string, duration time.Duration) tea.Cmd

ShowTemporaryToast creates a toast that auto-dismisses after the specified duration

func ShowToastWithAction

func ShowToastWithAction(toastType ToastType, message string, actionLabel string, actionCmd tea.Cmd) tea.Cmd

ShowToastWithAction creates a toast with an action button

func ShowUndoableToast

func ShowUndoableToast(message string, undoCmd tea.Cmd) tea.Cmd

ShowUndoableToast creates a toast with an undo action

func ShowWarning

func ShowWarning(message string) tea.Cmd

ShowWarning creates a command to show a warning toast

func ShowWarningWithTitle

func ShowWarningWithTitle(title, message string) tea.Cmd

ShowWarningWithTitle creates a command to show a warning toast with a title

Types

type DismissAllToastsMsg

type DismissAllToastsMsg struct{}

DismissAllToastsMsg dismisses all visible toasts

type DismissToastMsg

type DismissToastMsg struct {
	ID string
}

DismissToastMsg dismisses a specific toast by ID

type ShowToastMsg

type ShowToastMsg struct {
	Config ToastConfig
}

ShowToastMsg triggers a new toast notification

type Toast

type Toast struct {
	// contains filtered or unexported fields
}

Toast is a single notification

func NewToast

func NewToast(config ToastConfig) *Toast

NewToast creates a new toast notification

func (*Toast) Config

func (t *Toast) Config() ToastConfig

Config returns the toast's configuration

func (*Toast) Dismiss

func (t *Toast) Dismiss() tea.Cmd

Dismiss marks the toast as dismissed and starts fade out animation

func (*Toast) GetHeight

func (t *Toast) GetHeight() int

GetHeight returns the calculated toast height

func (*Toast) GetOpacity

func (t *Toast) GetOpacity() float64

GetOpacity returns the current opacity value

func (*Toast) GetWidth

func (t *Toast) GetWidth() int

GetWidth returns the toast width

func (*Toast) ID

func (t *Toast) ID() string

ID returns the toast's unique identifier

func (*Toast) Init

func (t *Toast) Init() tea.Cmd

Init initializes the toast

func (*Toast) IsDismissed

func (t *Toast) IsDismissed() bool

IsDismissed returns true if the toast has been dismissed

func (*Toast) IsExpired

func (t *Toast) IsExpired() bool

IsExpired returns true if the toast should be dismissed

func (*Toast) IsFadingOut

func (t *Toast) IsFadingOut() bool

IsFadingOut returns true if the toast is fading out

func (*Toast) SetValue

func (t *Toast) SetValue(value float64)

SetValue directly sets the toast opacity value

func (*Toast) SetWidth

func (t *Toast) SetWidth(width int)

SetWidth sets the toast width

func (*Toast) StartFadeIn

func (t *Toast) StartFadeIn() tea.Cmd

StartFadeIn starts the fade in animation

func (*Toast) Update

func (t *Toast) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update updates the toast state

func (*Toast) View

func (t *Toast) View() string

View renders the toast

type ToastAction

type ToastAction struct {
	Label   string
	Command tea.Cmd
}

ToastAction is an optional button in toast

type ToastActionMsg

type ToastActionMsg struct {
	ToastID string
	Action  *ToastAction
}

ToastActionMsg is fired when an action button is clicked

type ToastBuilder

type ToastBuilder struct {
	// contains filtered or unexported fields
}

ToastBuilder helps build complex toast configurations

func NewToastBuilder

func NewToastBuilder(toastType ToastType) *ToastBuilder

NewToastBuilder creates a new toast builder

func (*ToastBuilder) Build

func (b *ToastBuilder) Build() tea.Cmd

Build returns the configured toast command

func (*ToastBuilder) Dismissible

func (b *ToastBuilder) Dismissible(dismissible bool) *ToastBuilder

Dismissible sets whether the toast can be manually dismissed

func (*ToastBuilder) Persistent

func (b *ToastBuilder) Persistent() *ToastBuilder

Persistent makes the toast require manual dismissal

func (*ToastBuilder) WithAction

func (b *ToastBuilder) WithAction(label string, cmd tea.Cmd) *ToastBuilder

WithAction adds an action button

func (*ToastBuilder) WithDuration

func (b *ToastBuilder) WithDuration(duration time.Duration) *ToastBuilder

WithDuration sets the auto-dismiss duration

func (*ToastBuilder) WithIcon

func (b *ToastBuilder) WithIcon(icon string) *ToastBuilder

WithIcon sets a custom icon

func (*ToastBuilder) WithMessage

func (b *ToastBuilder) WithMessage(message string) *ToastBuilder

WithMessage sets the toast message

func (*ToastBuilder) WithPosition

func (b *ToastBuilder) WithPosition(position ToastPosition) *ToastBuilder

WithPosition sets the toast position

func (*ToastBuilder) WithTitle

func (b *ToastBuilder) WithTitle(title string) *ToastBuilder

WithTitle sets the toast title

type ToastConfig

type ToastConfig struct {
	Type        ToastType
	Message     string
	Title       string        // Optional
	Duration    time.Duration // Auto-dismiss time (0 = manual dismiss)
	Dismissible bool          // Can be dismissed with X button
	Position    ToastPosition
	Icon        string       // Optional icon
	Action      *ToastAction // Optional action button
}

ToastConfig configures toast behavior

func DefaultToastConfig

func DefaultToastConfig(toastType ToastType) ToastConfig

DefaultToastConfig returns sensible defaults for a toast

type ToastExpiredMsg

type ToastExpiredMsg struct {
	ID string
}

ToastExpiredMsg is fired when a toast auto-dismisses

type ToastManager

type ToastManager struct {
	// contains filtered or unexported fields
}

ToastManager manages multiple toasts with queue

func NewToastManager

func NewToastManager() *ToastManager

NewToastManager creates a new toast manager

func (*ToastManager) ClearQueue

func (m *ToastManager) ClearQueue()

ClearQueue clears all queued toasts

func (*ToastManager) DismissAll

func (m *ToastManager) DismissAll() tea.Cmd

DismissAll dismisses all visible toasts

func (*ToastManager) DismissToast

func (m *ToastManager) DismissToast(id string) tea.Cmd

DismissToast dismisses a specific toast by ID

func (*ToastManager) GetMaxToasts

func (m *ToastManager) GetMaxToasts() int

GetMaxToasts returns the maximum number of visible toasts

func (*ToastManager) GetPosition

func (m *ToastManager) GetPosition() ToastPosition

GetPosition returns the default toast position

func (*ToastManager) GetQueueLength

func (m *ToastManager) GetQueueLength() int

GetQueueLength returns the number of queued toasts

func (*ToastManager) GetToasts

func (m *ToastManager) GetToasts() []*Toast

GetToasts returns the list of visible toasts

func (*ToastManager) HasToasts

func (m *ToastManager) HasToasts() bool

HasToasts returns true if there are visible toasts

func (*ToastManager) Init

func (m *ToastManager) Init() tea.Cmd

Init initializes the toast manager

func (*ToastManager) IsEnabled

func (m *ToastManager) IsEnabled() bool

IsEnabled returns whether toast notifications are enabled

func (*ToastManager) RemoveToast

func (m *ToastManager) RemoveToast(id string)

RemoveToast removes a toast from the visible list

func (*ToastManager) SetEnabled

func (m *ToastManager) SetEnabled(enabled bool)

SetEnabled enables or disables toast notifications

func (*ToastManager) SetMaxToasts

func (m *ToastManager) SetMaxToasts(max int)

SetMaxToasts sets the maximum number of visible toasts

func (*ToastManager) SetPosition

func (m *ToastManager) SetPosition(pos ToastPosition)

SetPosition sets the default toast position

func (*ToastManager) SetSize

func (m *ToastManager) SetSize(width, height int)

SetSize sets the manager's dimensions

func (*ToastManager) ShowError

func (m *ToastManager) ShowError(message string) tea.Cmd

ShowError displays an error toast

func (*ToastManager) ShowInfo

func (m *ToastManager) ShowInfo(message string) tea.Cmd

ShowInfo displays an info toast

func (*ToastManager) ShowLoading

func (m *ToastManager) ShowLoading(message string) tea.Cmd

ShowLoading displays a loading toast

func (*ToastManager) ShowSuccess

func (m *ToastManager) ShowSuccess(message string) tea.Cmd

ShowSuccess displays a success toast

func (*ToastManager) ShowToast

func (m *ToastManager) ShowToast(config ToastConfig) tea.Cmd

ShowToast displays a new toast notification

func (*ToastManager) ShowWarning

func (m *ToastManager) ShowWarning(message string) tea.Cmd

ShowWarning displays a warning toast

func (*ToastManager) Stats

func (m *ToastManager) Stats() string

Stats returns statistics about the toast manager

func (*ToastManager) Update

func (m *ToastManager) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update updates all toasts and handles toast-related messages

func (*ToastManager) View

func (m *ToastManager) View() string

View renders all visible toasts

type ToastPosition

type ToastPosition int

ToastPosition defines where toast appears

const (
	TopRight ToastPosition = iota
	TopCenter
	TopLeft
	BottomRight
	BottomCenter
	BottomLeft
)

func (ToastPosition) String

func (p ToastPosition) String() string

String returns the string representation of a ToastPosition

type ToastStylePreset

type ToastStylePreset struct {
	Name            string
	BorderStyle     lipgloss.Border
	BorderColor     string
	BackgroundColor string
	TextColor       string
}

ToastStylePresets provides pre-configured style combinations

type ToastTickMsg

type ToastTickMsg struct {
	ID string
}

ToastTickMsg is sent periodically to update toast state

type ToastType

type ToastType int

ToastType defines notification type

const (
	ToastInfo ToastType = iota
	ToastSuccess
	ToastWarning
	ToastError
	ToastLoading
)

func (ToastType) String

func (t ToastType) String() string

String returns the string representation of a ToastType

Jump to

Keyboard shortcuts

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