notification

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MethodAuto uses the terminal when it is known to understand the
	// sequence, and the system otherwise. The default.
	MethodAuto = "auto"
	// MethodTerminal always asks the terminal, for one the allowlist does
	// not know. A terminal that does not understand it prints it.
	MethodTerminal = "terminal"
	// MethodSystem always uses the platform's own notifier — notify-send
	// on Linux, osascript on macOS, which posts as Script Editor.
	MethodSystem = "system"
)

Delivery methods for NewNotifier.

Variables

This section is empty.

Functions

func Alert added in v0.0.27

func Alert(n *Notifier, s *SoundPlayer, title, body string) string

Alert posts one message's notification and plays its sound, and returns what the caller must write to the terminal: the notification's sequence, the bell, both, or "".

Where the notifier and the player both fall back to the bell, they ring it through one limit, the notifier's. The terminal has one bell, and with a limit each the two only agree while they are asked at the same instants: once one has rung without the other, each rings once an interval on its own, and a burst rings twice.

func ResolveMethod

func ResolveMethod(v string) string

ResolveMethod normalises a configured value, falling back to the default for an empty or unrecognised one: a typo in a cosmetic setting should cost the user the setting, not the client.

Types

type Notifier

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

Notifier sends desktop notifications.

func NewNotifier

func NewNotifier(enabled, showPreview bool, method string) *Notifier

NewNotifier creates a new notification dispatcher.

func (*Notifier) Close added in v0.0.27

func (n *Notifier) Close()

Close stops the system path from starting anything new, drops the notification waiting to be posted, if any, and waits for a notifier process that is still running — at most about helperTimeout, after which that process is killed.

Nothing in the app calls it, and nothing needs to: the worker only lives while a process does, and leaving that process behind at exit is what exiting has always done. The tests call it, so that no worker outlives the test that started it.

func (*Notifier) Notify

func (n *Notifier) Notify(title, body string) string

Notify posts a desktop notification and returns the escape sequence the caller must write to the terminal, or "" when there is nothing to write.

It returns a sequence rather than writing one because this process does not own the terminal: Bubble Tea does, and a goroutine writing to the same file descriptor can land in the middle of a frame. The caller hands the result to tea.Raw, which puts it in the renderer's own output buffer, under the renderer's own lock, between frames.

The system path has no such problem and is taken here, in the background — notify-send and osascript are processes, and waiting on one would stall the event loop for as long as the desktop takes to answer. One of them runs at a time: what arrives meanwhile is folded into a single notification behind it, so a burst of messages costs two processes rather than one each.

type SoundPlayer

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

SoundPlayer plays notification sounds.

func NewSoundPlayer

func NewSoundPlayer(enabled bool) *SoundPlayer

NewSoundPlayer creates a new sound player.

func (*SoundPlayer) Close added in v0.0.27

func (s *SoundPlayer) Close()

Close stops the player from starting anything new, and waits for one that is still running — at most about helperTimeout for each player it tries, after which that player is killed.

Nothing in the app calls it, and that is fine for the reason Notifier.Close gives: the goroutine lives only as long as the player does, and exiting leaves that player behind as it always has. The tests call it, so that no player outlives the test that started it.

type TerminalSupport

type TerminalSupport int

TerminalSupport is what a terminal will accept.

const (
	// TerminalNone means send nothing: a terminal that does not understand
	// the sequence PRINTS it, which would drop `]777;notify;Ana;hi` into
	// the middle of somebody's chat. The failure is asymmetric, so this is
	// an allowlist and the default answer is no.
	TerminalNone TerminalSupport = iota
	// TerminalTitleAndBody takes OSC 777.
	TerminalTitleAndBody
	// TerminalBodyOnly takes OSC 9.
	TerminalBodyOnly
)

Jump to

Keyboard shortcuts

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