Documentation
¶
Overview ¶
Package detect derives a session state from its terminal output alone: desktop-notification escapes (OSC 9, OSC 777;notify, OSC 99) and BEL mean the program wants the user, output means it is working, and silence for IdleAfter means it is idle. It reports transitions only and runs no timer while nothing can change.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
IdleAfter time.Duration // default 3s
// OnState receives each state change (wire.State*) and its source.
OnState func(state, source string)
// OnNotify receives every notification the program emitted.
OnNotify func(Notification)
Clock Clock // default: real time
}
Config configures a Detector. Callbacks run synchronously, one at a time, with the detector locked: they must not call back into the detector.
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector is the output-derived state machine of one session. States: working, idle, waiting_input, exited.
- Any output: idle → working. waiting_input is sticky until input is written to the program (Input): a program that asked for the user usually redraws its prompt afterwards, which is not work.
- Output within redrawGrace of a resize (Resized) starts no work: the program redraws for the new size. Reopening a session from the app resizes it, and that redraw must neither list the session as working nor override its hook-derived state.
- No output for IdleAfter while working → idle (one timer, re-armed lazily: it fires at most once per IdleAfter while output flows).
- OSC 9 / 777;notify / 99, or BEL outside a string sequence → notification + waiting_input.
- Exited → exited, final.
func New ¶
New returns a detector in state working (the program just started) with the idle timer armed.
func (*Detector) Feed ¶
Feed processes a chunk of program output. Escape sequences may be split across chunks. A chunk of DEC private mode sets and resets and key modifier options only (`CSI ? Pm h/l`, `CSI > Pp;Pv m`) changes nothing on screen and is not work: Oh My Pi on Windows re-enables bracketed paste every second while it waits, and Antigravity CLI bracketed paste and modifyOtherKeys every 2.1 s. Neither is output within redrawGrace of a resize (notifications in it still count).
func (*Detector) Input ¶
func (d *Detector) Input()
Input records that input was written to the program, which ends a sticky waiting_input: the next output counts as work again.
func (*Detector) Resized ¶ added in v0.22.0
func (d *Detector) Resized()
Resized records that the terminal was resized: output for redrawGrace from now is the program redrawing, not work. Safe to call under locks the state callbacks take.
func (*Detector) SetIdleAfter ¶
SetIdleAfter changes the quiet period (the daemon's idle_after_ms).
type Notification ¶
type Notification struct {
Title string
Body string
Bell bool // a bare BEL rather than an OSC notification
}
Notification is one notification the program emitted.