flash

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package flash provides state management for transient status messages in Bubble Tea applications.

A typical TUI shows a brief "Approved #123" or "Error: ..." message that auto-clears after a few seconds. Both the message and a monotonic ID are tracked so that stale ClearMsg ticks never wipe a newer message.

The package is pure state - the application owns the [tea.Tick] scheduling and the rendering. flash only manages the set/clear lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClearMsg

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

ClearMsg is sent after the flash duration expires. Pass it to State.Clear in the application's Update loop.

type State

type State struct {
	Msg string
	Err bool
	// contains filtered or unexported fields
}

State tracks a transient status message with expiry.

func (*State) Active

func (s *State) Active() bool

Active reports whether a flash message is currently showing.

func (*State) Clear

func (s *State) Clear(msg ClearMsg)

Clear resets the flash only when the ClearMsg ID matches the current flash. A stale clear (from an earlier Set) is silently ignored.

func (*State) Set

func (s *State) Set(msg string, isErr bool) ClearMsg

Set updates the flash message, increments the internal ID and returns a ClearMsg for use with [tea.Tick]. The caller schedules the tick:

clear := m.flash.Set("Done", false)
return m, tea.Tick(5*time.Second, func(time.Time) tea.Msg { return clear })

Jump to

Keyboard shortcuts

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