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 ¶
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 ¶
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) Next ¶
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 ¶
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.
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 ¶
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.