Documentation
¶
Overview ¶
Package notificationcenter is a persistent multi-item panel over a bounded notification queue — distinct from toast.Model's transient, one-at-a-time popup, this composites ALL currently-queued notifications simultaneously in a single panel, colored via the same widgets.Variant-to-color convention toast and widgets.Alert already use.
Stability: experimental. Its API may change in any minor release.
Example ¶
A notification center queues messages and draws them in one panel over the base screen, at most maxVisible at a time.
package main
import (
"fmt"
"strings"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/notificationcenter"
"github.com/ows4444/tui/widgets"
)
func main() {
m := notificationcenter.New(2, 24)
m.Push(notificationcenter.Notification{Message: "build passed", Variant: widgets.VariantSuccess})
m.Push(notificationcenter.Notification{Message: "disk almost full", Variant: widgets.VariantWarning})
base := strings.TrimRight(strings.Repeat(strings.Repeat(" ", 40)+"\n", 8), "\n")
out := ansi.StripANSI(m.Render(base))
fmt.Println(strings.Contains(out, "build passed"), strings.Contains(out, "disk almost full"))
}
Output: true true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
// Notifications is the bounded queue, oldest first. Push maintains the
// MaxVisible bound; Notifications can also be set directly as long as
// that invariant is respected.
Notifications []Notification
// MaxVisible caps how many notifications the queue holds at once. Push
// drops the oldest entry once the queue would exceed it.
MaxVisible int
// Width, if positive, wraps each notification's message so every
// rendered line's ansi.Width stays within it (mirrors widgets.Alert's
// width behavior). 0 sizes the panel to its widest content line.
Width int
Theme theme.Theme
// Raw, when true, draws notification messages unchanged. By default they
// are sanitised (ansi.Sanitize) so untrusted text cannot carry terminal
// escape sequences.
Raw bool
// contains filtered or unexported fields
}
Model is a bounded queue of Notifications rendered as a single panel listing every entry currently queued, unlike toast.Model which shows only one notification at a time.
func New ¶
New returns an empty Model bounded to maxVisible notifications, rendering at width (0 sizes to content).
func (Model) LayoutNode ¶
LayoutNode returns the notification panel as an ordinary layout.Node: each message word-wrapped to the width the panel is given and coloured by its Variant, inside a bordered box. An empty queue measures as nothing and renders blank. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the queue as plain text for accessible output (see tui.Linearizer): "Notifications, N" and one line per notification, oldest first, "<kind> K of N: <message>" with the Variant in words, or "" when the queue is empty.
func (*Model) Push ¶
func (m *Model) Push(n Notification)
Push appends n to the queue. If the queue then holds more than MaxVisible notifications, the oldest entry (index 0) is dropped so the queue never exceeds MaxVisible — only the most recent notifications are kept.
func (Model) Render ¶
Render composites a panel listing every currently-queued notification over base, each line colored via n.Variant.Color(m.Theme) — the same convention toast.Model and widgets.Alert use. With an empty queue it returns base unchanged rather than drawing an empty panel.
func (Model) SetTheme ¶
SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).
type Notification ¶
Notification is one queued entry: a message and the Variant that colors it, per widgets.Variant's shared convention.