notificationcenter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func New(maxVisible, width int) Model

New returns an empty Model bounded to maxVisible notifications, rendering at width (0 sizes to content).

func (Model) LayoutNode

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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

func (m Model) Render(base string) string

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

func (m Model) SetTheme(t theme.Theme) Model

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

func (Model) Tokens

func (m Model) Tokens() theme.Tokens

Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentNotificationCenter, ...) and then by WithTokens.

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override. Nil fields inherit from the theme, so only the roles tok names change; the theme and every other widget are untouched. A second call replaces the first.

type Notification

type Notification struct {
	Message string
	Variant widgets.Variant
}

Notification is one queued entry: a message and the Variant that colors it, per widgets.Variant's shared convention.

Jump to

Keyboard shortcuts

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