watcher

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package watcher monitors a directory for changes to known compose filenames and delivers snapshot messages to the Bubble Tea runtime via tea.Cmd.

Index

Constants

This section is empty.

Variables

View Source
var ErrCreateWatcher = errors.New("create watcher")

ErrCreateWatcher is returned when watcher initialisation fails.

Functions

This section is empty.

Types

type FileWatcher

type FileWatcher interface {
	Events() chan fsnotify.Event
	Errors() chan error
	Add(name string) error
	Close() error
}

FileWatcher abstracts a filesystem watcher so the event loop is testable without a real filesystem. The production implementation wraps *fsnotify.Watcher.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service monitors a directory for filesystem events on known compose filenames and delivers msgs.FileAvailabilityChanged snapshots to the Bubble Tea runtime. extraFile is an additional basename to track beyond the scanner's known filenames (e.g. a manually specified project file). When empty, only the scanner's known filenames are tracked.

func (*Service) Close

func (w *Service) Close() error

Close stops the background event loop and releases the underlying fsnotify watcher. Safe to call more than once; subsequent calls are no-ops.

func (*Service) Dir

func (w *Service) Dir() string

Dir returns the directory this Service monitors.

func (*Service) Next

func (w *Service) Next() tea.Cmd

Next returns a tea.Cmd that blocks until the next availability snapshot is ready and returns it as a msgs.FileAvailabilityChanged. After receiving a message in Update, call Next again to continue listening. Returns nil if the watcher is closed.

func (*Service) Snapshot

func (w *Service) Snapshot() tea.Cmd

Snapshot returns a tea.Cmd that delivers the current filesystem state as a msgs.FileAvailabilityChanged without waiting for a change event. Extra files passed to New are included in the scan.

func (*Service) Start

func (w *Service) Start(sendMsg func(tea.Msg))

Start begins the background event loop. sendMsg routes non-domain messages (e.g. fsnotify errors) into the Bubble Tea event loop. Must be called once after the tea.Program is created. Safe to call multiple times; subsequent calls are no-ops.

type Watcher

type Watcher interface {
	// Dir returns the directory being monitored.
	Dir() string
	// Start begins the background event loop. sendMsg routes non-domain
	// messages (e.g. errors) into the Bubble Tea event loop. Must be
	// called once after the tea.Program is created.
	Start(sendMsg func(tea.Msg))
	// Next returns a tea.Cmd that blocks until the next snapshot is ready.
	// Re-call after each FileAvailabilityChanged to continue listening.
	Next() tea.Cmd
	// Snapshot returns a tea.Cmd that delivers the current filesystem state
	// as a msgs.FileAvailabilityChanged without waiting for a change event.
	Snapshot() tea.Cmd
	// Close stops the background goroutine and releases resources.
	Close() error
}

Watcher monitors a directory for filesystem changes and delivers msgs.FileAvailabilityChanged snapshots to the Bubble Tea runtime.

func New

func New(dir string, extraFile string, sc scanner.Scanner) (Watcher, error)

New creates a Watcher that monitors dir. extraFile is an additional basename to track (e.g. a manually specified project file). Pass "" to only track the scanner's known filenames. On failure, nil is returned alongside the error. Call Start to begin the background event loop.

func NewWithFileWatcher

func NewWithFileWatcher(
	dir string,
	extraFile string,
	sc scanner.Scanner,
	fw FileWatcher,
) (Watcher, error)

NewWithFileWatcher creates a Watcher with the given FileWatcher implementation. Intended for testing with a fake FileWatcher; production code should use New instead. Call Start to begin the background event loop.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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