termnotify

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 10 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 termnotify asks the terminal to show a desktop notification. Terminals never agreed on one sequence, so it picks one by what the terminal is: OSC 99 for kitty, OSC 9 for iTerm2, WezTerm and Ghostty, OSC 777 notify for foot, and a bell everywhere else, which most terminals turn into a badge, a bounce of the dock icon or a flash. Inside tmux the sequence is wrapped so tmux passes it on to the terminal it runs in, when tmux's allow-passthrough option lets it.

Index

Constants

View Source
const (
	MaxTitle = 64
	MaxBody  = 256
)

The longest title and body sent, in runes. Notifications show little more, and the protocols' own limits are larger.

Variables

This section is empty.

Functions

func Passthrough

func Passthrough(seq string) string

Passthrough wraps seq for tmux to pass on to the terminal outside it: DCS tmux ; seq ST, with each ESC in seq doubled.

func Sequence

func Sequence(p Protocol, title, body string) string

Sequence is the escape sequence that asks, by p, for a notification with title and body. Control characters become spaces, and both are cut to MaxTitle and MaxBody. For Bell it is BEL, and for Off empty.

Types

type Notifier

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

Notifier sends notifications to a terminal, and keeps the time of the user's last key, so a caller can notify only someone who has looked away. Its methods are safe to call from any goroutine, and on a nil Notifier do nothing.

func ForTerminal

func ForTerminal(w io.Writer) *Notifier

ForTerminal is New for w, mdsh's own terminal, detected from the process's environment, and from tmux when it runs under tmux.

func New

func New(w io.Writer, p Protocol, tmux bool) *Notifier

New sends to w, the terminal, by p; with tmux set, wrapped for tmux to pass on. A nil w or Off gives a nil Notifier.

func (*Notifier) Idle

func (n *Notifier) Idle() time.Duration

Idle is how long since the user's last key, or since n was made.

func (*Notifier) Notify

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

Notify asks the terminal to show title and body.

func (*Notifier) Protocol

func (n *Notifier) Protocol() Protocol

Protocol is what n sends by: Off for a nil Notifier.

func (*Notifier) Seen

func (n *Notifier) Seen()

Seen notes a key from the user.

type Protocol

type Protocol int

Protocol is a way to ask for a notification.

const (
	// Bell rings the terminal's bell, BEL.
	Bell Protocol = iota
	// OSC9 is iTerm2's OSC 9 ; text, which WezTerm and Ghostty take
	// too.
	OSC9
	// OSC99 is kitty's OSC 99, with a title and a body.
	OSC99
	// OSC777 is urxvt's OSC 777 ; notify ; title ; body, which foot
	// takes.
	OSC777
	// Off sends nothing.
	Off
)

func Detect

func Detect(env func(string) string) Protocol

Detect picks the protocol for the terminal env describes. MDSH_NOTIFY overrides it: off, bell, osc9, osc99 or osc777. Inside tmux, where TERM and TERM_PROGRAM name tmux, use DetectTmux.

func DetectTmux

func DetectTmux(env func(string) string, t Tmux) Protocol

DetectTmux picks the protocol inside tmux, from what tmux says of the terminal outside it. A notification needs passthrough; without it, a bell, which tmux marks on the window and passes on as its bell-action says.

func Parse

func Parse(s string) (Protocol, bool)

Parse reads a protocol's name, as MDSH_NOTIFY gives it.

func (Protocol) String

func (p Protocol) String() string

type Tmux

type Tmux struct {
	// TermName is the client's TERM, such as xterm-kitty, and TermType
	// the terminal's own name and version, from XTVERSION, such as
	// "iTerm2 3.5.4" (tmux 3.3 and later).
	TermName, TermType string
	// Passthrough is the pane's allow-passthrough option: off, on or
	// all.
	Passthrough string
}

Tmux is what tmux says of the terminal its client runs in, and of the pane mdsh runs in.

func AskTmux

func AskTmux(env func(string) string) Tmux

AskTmux asks the tmux server mdsh runs under about its client and pane. It gives the zero Tmux, which DetectTmux takes as no passthrough, if tmux doesn't answer within half a second.

Jump to

Keyboard shortcuts

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