diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 19:42:30 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 19:42:30 +0300 |
| commit | 16e413799363871c1efd73527fba299dfdfadfd3 (patch) | |
| tree | 36627063d7d0b80f824cc9abe6848d860b082c3e /internal/eventloop.go | |
| parent | 0b454f367374e8cb97927627dacd0f1b216fe5ad (diff) | |
refactor: extract outputFormatter collaborator from eventLoop
The printCb and warningCb function fields on eventLoop bundled two
distinct concerns (pair emission and warning delivery) directly on the
event-processing struct. This commit extracts them into a dedicated
outputFormatter type that owns these callbacks plus emit() and
notifyWarning() helper methods.
outputFormatter is embedded (not pointed-to) in eventLoop so that
existing call sites — including tests that write el.printCb = ... and
el.warningCb = ... directly — require no changes beyond the three
struct-literal sites in eventloop_filter_test.go that used field
initialiser syntax.
fdTracker and commResolver were already proper collaborator types; only
the output concern needed extraction.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/eventloop.go')
| -rw-r--r-- | internal/eventloop.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go index fc82ee4..0fe327c 100644 --- a/internal/eventloop.go +++ b/internal/eventloop.go @@ -48,9 +48,8 @@ type eventLoop struct { pendingHandles *pendingHandleTracker // TID → pathname from name_to_handle_at, for open_by_handle_at correlation fdTracker *fdTracker // fd table and procfs resolution cache commResolver *commResolver + outputFormatter // pair-emission and warning-notification callbacks (embedded collaborator) rawHandlers map[types.EventType]rawEventHandler - printCb func(ep *event.Pair) // Callback to print the event - warningCb func(message string) // Optional callback for non-fatal event processing warnings cfg eventLoopConfig // Statistics @@ -92,10 +91,14 @@ func newEventLoop(cfg eventLoopConfig) (*eventLoop, error) { pendingHandles: newPendingHandleTracker(), fdTracker: fdState, commResolver: commState, - rawHandlers: make(map[types.EventType]rawEventHandler), - printCb: func(ep *event.Pair) { fmt.Println(ep); ep.Recycle() }, - cfg: cfg, - done: make(chan struct{}), + // Default printCb prints each pair to stdout then recycles it; callers + // (e.g. TUI, headless-parquet) replace this via configureEventLoopOutput. + outputFormatter: outputFormatter{ + printCb: func(ep *event.Pair) { fmt.Println(ep); ep.Recycle() }, + }, + rawHandlers: make(map[types.EventType]rawEventHandler), + cfg: cfg, + done: make(chan struct{}), } el.SetFilter(cfg.filter) el.initRawHandlers() |
