From 16e413799363871c1efd73527fba299dfdfadfd3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 May 2026 19:42:30 +0300 Subject: refactor: extract outputFormatter collaborator from eventLoop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/eventloop.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'internal/eventloop.go') 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() -- cgit v1.2.3