Documentation
¶
Index ¶
Constants ¶
const ExitInterrupt = 130
ExitInterrupt is the exit code for interrupt (130 = 128 + SIGINT).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages graceful interrupt handling with double Ctrl+C detection. First Ctrl+C triggers early stop with continuation. Second Ctrl+C within the window triggers abort.
func NewHandler ¶
NewHandler creates a handler that listens for SIGINT/SIGTERM. Returns the handler and a context that is canceled on first interrupt.
func NewHandlerWithOptions ¶
NewHandlerWithOptions creates a handler with injectable dependencies. Used by tests to inject mock signal channels, exit functions, and clocks.
func (*Handler) Stop ¶
func (h *Handler) Stop()
Stop cleans up the handler. Should be called when done.
func (*Handler) WaitForDecision ¶
WaitForDecision waits for the interrupt window and returns the user's intent. If a second Ctrl+C is received within the window, returns Abort. Otherwise, returns Continue after the timeout. The message parameter is displayed to guide the user.
func (*Handler) WasInterrupted ¶
WasInterrupted returns true if at least one interrupt was received.
type Options ¶
type Options struct {
SigCh <-chan os.Signal
ExitFunc func(int)
NowFunc func() time.Time
// Stderr is the writer for user-facing messages.
// Must be safe for concurrent writes from multiple goroutines.
// Defaults to os.Stderr which is safe at the OS level.
Stderr io.Writer
}
Options holds injectable dependencies for testing.