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 ¶
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 ¶
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 ¶
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 ¶
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.
type Notification ¶
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.
func ParseTerminal ¶
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.