termnotify

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 5 Imported by: 0 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 encodes a notification as a terminal escape sequence for the fixed set of terminals Sidecar supports.

It exists for one situation: Sidecar running directly inside an ordinary SSH terminal. There is no local viewer to hand the event to, and the remote host has no desktop notification service or audio device worth reaching — the outer terminal on the far end of the connection is the only thing that can get the user's attention.

The package is deliberately state-free and byte-exact. Every sequence it produces is asserted literally in the tests, because the contract here is the bytes themselves: a sequence that is one character wrong is not a degraded notification, it is arbitrary text painted into the user's terminal. For the same reason the sequences are spelled out here rather than borrowed from a helper library, whose choice of terminator could change under us.

Nothing in this package performs I/O, reads configuration, or knows about Bubble Tea. Callers supply the environment lookup and the writer.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedTerminal is returned for any terminal outside the fixed
	// matrix. There is no generic fallback on purpose: BEL or a guessed escape
	// in an unknown terminal is noise or garbage on screen, not a notification.
	ErrUnsupportedTerminal = errors.New("termnotify: unsupported terminal")
	// ErrEmptyNotification refuses a sequence with nothing left to say, which is
	// what a title and body made entirely of control characters sanitize down to.
	ErrEmptyNotification = errors.New("termnotify: notification has no displayable text")
)

Functions

func Encode

func Encode(term Terminal, n Notification, tmux bool) (string, error)

Encode returns the exact bytes that deliver n through term.

tmux reports whether this process is inside a tmux client, in which case every sequence is wrapped in tmux's DCS passthrough so it reaches the outer terminal instead of being swallowed by tmux.

func InsideTmux

func InsideTmux(getenv func(string) string) bool

InsideTmux reports whether this process is running in a tmux client, which is the one fact that changes how a sequence has to be framed.

func Sanitize

func Sanitize(s string) string

Sanitize removes everything that could terminate or redirect the sequence carrying it.

Notification titles and bodies are attacker-influenced: they carry branch names, agent output and workspace names from outside Sidecar. An ESC, a BEL or a string terminator in one of them would end the OSC early and leave the remainder to be executed as terminal commands. Newlines and tabs collapse to single spaces for the same reason, and format characters go because a body containing U+202E would render the notification backwards.

Types

type Detection

type Detection struct {
	Terminal Terminal
	// Marker names the environment variable that identified the terminal, so
	// status can explain the answer instead of asserting it.
	Marker string
	Reason string
}

Detection is the answer to "which terminal is on the other end of this connection". Reason is honest status text for Configuration and the CLI when nothing was identified: this transport reports unavailable rather than guessing, because a guess sends the wrong sequence to a real terminal.

func Detect

func Detect(getenv func(string) string) Detection

Detect identifies the outer terminal from known environment markers only.

Every marker is evaluated rather than the first match winning. Two different terminals claiming one process is ambiguous — a stale KITTY_WINDOW_ID inherited into a Ghostty window, say — and choosing between them would send one terminal's private sequence to another. Ambiguity is reported as unavailable, which the user resolves by naming a terminal explicitly.

func (Detection) OK

func (d Detection) OK() bool

OK reports whether a supported terminal was identified.

type Notification

type Notification struct {
	ID    string
	Title string
	Body  string
}

Notification is the bounded input to an encoder. ID correlates the two chunks of a Kitty notification and is ignored by the OSC 9 encoders.

type Terminal

type Terminal string

Terminal names one supported outer terminal. These values match the notifications.ssh.terminal config vocabulary.

const (
	Ghostty Terminal = "ghostty"
	ITerm2  Terminal = "iterm2"
	WezTerm Terminal = "wezterm"
	Kitty   Terminal = "kitty"
)

func ParseTerminal

func ParseTerminal(name string) (Terminal, bool)

ParseTerminal resolves a configured terminal name. It accepts only the exact vocabulary; a near miss is a refusal, never a guess at what was meant.

func Supported

func Supported() []Terminal

Supported lists the terminals with a fixed encoder, in config order.

Jump to

Keyboard shortcuts

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