interrupt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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 Behavior

type Behavior int

Behavior defines what happens after the first Ctrl+C.

const (
	// Continue means continue with partial work (e.g., transcribe partial recording).
	Continue Behavior = iota
	// Abort means discard all work and exit.
	Abort
)

func (Behavior) String

func (b Behavior) String() string

String returns the string representation of the Behavior.

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

func NewHandler(parent context.Context) (*Handler, context.Context)

NewHandler creates a handler that listens for SIGINT/SIGTERM. Returns the handler and a context that is canceled on first interrupt.

func NewHandlerWithOptions

func NewHandlerWithOptions(parent context.Context, opts Options) (*Handler, context.Context)

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

func (h *Handler) WaitForDecision(message string) Behavior

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

func (h *Handler) WasInterrupted() bool

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.

Jump to

Keyboard shortcuts

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