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.
- 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.
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) 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.