livepanes

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package livepanes owns the lifecycle every live-refreshed pane kind shares.

livewatch answers two questions — has anything changed, and is the result different from what is on screen. Everything between those two answers was, until this package, written out once per pane kind per surface: start a watcher lazily inside a tea.Cmd, adopt it across a project switch or stop the one that lost the race, point it at the panes that are actually open, re-arm a one-shot listener on every signal, and give every descriptor back on teardown. Six copies of that, differing only in which map they walked and which message type they carried, is six chances for a new pane kind to silently not refresh — which is exactly what happened to the Resource leaf, which has none of it.

So a surface registers its kinds once and inherits the rest:

set := livepanes.NewSet("workspace",
    livepanes.Binding{Kind: "doc", Targets: p.docTargets, Refresh: p.refreshDocs},
    ...)

and calls Set.Reconcile once per update, Set.Handle on every message, and Set.Stop on teardown. What a kind still answers for itself is only what is genuinely its own: what to watch, and how to re-read it. Suppression vetoes, scroll preservation and the no-change gate stay with the pane, because each kind preserves different UI state across a re-read.

What to watch

A Binding reports the panes that are on screen, not every pane that exists. On macOS each registration costs a descriptor per file in the watched directory, so watching a background tab in a directory nobody is looking at is a real cost paid for a frame nobody sees. The pane that comes back into view re-reads on focus instead; the no-change gate means an unchanged file costs one read and no repaint.

Startup

Nothing here runs on the startup path. Watchers are created from inside a tea.Cmd the first time a kind has something to watch, so a session that never opens a pane never opens a descriptor for one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Owns

func Owns(owner string, msg tea.Msg) bool

Owns reports whether msg belongs to a Set with this owner. Surfaces share a message bus, so a host uses this to classify a background result it must deliver whether or not it is the visible surface.

Types

type Binding

type Binding struct {
	// Kind identifies this binding within its Set and travels in the messages
	// it produces. It must be stable and unique per Set.
	Kind string

	// Config tunes the watcher. The zero value takes livewatch's defaults,
	// which suit a pane reading one file. A kind whose store moves in bursts —
	// a td store several writes deep, a repository mid-rebase — should settle
	// longer, and say what the settle buys.
	Config livewatch.Config

	// Targets is what to watch right now: the visible panes of this kind, and
	// nothing else. It runs on the update goroutine on every reconcile, so it
	// must be cheap — read cached resolutions and open tabs, never walk a tree
	// or shell out. Returning nothing releases the registrations while leaving
	// the watcher usable.
	Targets func() []livewatch.Target

	// Prepare, when set, returns commands that resolve whatever Targets needs
	// before it can answer — where td keeps its store, where git keeps its
	// administrative files. It runs on every reconcile, so the host must cache
	// the answer and guard against resolving the same thing twice.
	Prepare func() tea.Cmd

	// Refresh re-reads the visible panes of this kind and returns the commands
	// carrying the results. The host owns the suppression veto: a refresh it
	// declines must stay owed, not be dropped.
	Refresh func() []tea.Cmd

	// Owed, when set, reports whether any pane of this kind has a re-read it
	// has not performed — a change that arrived while the host was vetoing
	// refreshes. It is what makes "the change lands as soon as the veto lifts"
	// true rather than aspirational: without it, a signal that arrives while a
	// modal, an overlay or a pane search owns the screen is remembered by the
	// pane and then never driven again, and the pane stays wrong until some
	// later write happens to arrive.
	//
	// Reconcile retries an owed refresh on every pass. That is cheap because a
	// still-vetoed refresh declines without reading anything.
	Owed func() bool
}

Binding is what one pane kind on one surface answers for itself.

type ChangedMsg

type ChangedMsg struct {
	Owner string
	Kind  string
}

ChangedMsg says the targets of one kind moved and its panes should re-read.

type Set

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

Set owns one surface's watchers, one per registered kind.

A Set is used only from the update goroutine. The watchers it holds are themselves concurrency-safe; nothing here needs to be.

func NewSet

func NewSet(owner string, epoch func() uint64, bindings ...Binding) *Set

NewSet registers the kinds of one surface. owner distinguishes this surface's messages from another's on the shared bus. epoch may be nil for a surface with no project epoch, in which case every message carries zero.

func (*Set) Handle

func (s *Set) Handle(msg tea.Msg) (tea.Cmd, bool)

Handle processes a live-refresh message, reporting whether msg was one of this Set's.

func (*Set) Kinds

func (s *Set) Kinds() []string

Kinds lists the registered kinds in registration order. It is what a parity test asserts against: claiming a message is not the same as having a binding to answer it with, and a test that checks only the former passes against a surface that quietly stopped refreshing one of its panes.

func (*Set) Reconcile

func (s *Set) Reconcile() tea.Cmd

Reconcile brings every watch set in line with the panes that are actually on screen, starting and releasing watchers as panes come and go.

Call it once per update rather than from each of the places that create, close, retarget or restore a pane. Those call sites are spread across pane creation, tab selection, layout decode, leaf close and project switch, and missing one shows up as either a pane that never updates or a watcher that outlives its pane — both silent. Reconciling from one place makes "the watch set matches the visible pane set" hold by construction.

func (*Set) Stop

func (s *Set) Stop()

Stop releases every descriptor this Set holds.

livewatch.Stop blocks until the watcher goroutine has drained, so this runs detached: a host calls it from the quit and project-switch boundary, and stalling there would stall the switch. It is idempotent, because that boundary can run twice around a switch.

func (*Set) Watcher

func (s *Set) Watcher(kind string) *livewatch.PathWatcher

Watcher returns the watcher for a kind, or nil when none is running. It exists for tests that assert descriptors are given back.

type WatchStartedMsg

type WatchStartedMsg struct {
	Owner   string
	Kind    string
	Epoch   uint64
	Watcher *livewatch.PathWatcher
}

WatchStartedMsg carries a watcher created off the update goroutine back to the Set that asked for it.

It must always reach Set.Handle, including for a project the user has since switched away from. It deliberately does not implement the hosts' stale-epoch interface: a host that dropped it would leak the watcher it carries — nothing else holds a reference to stop it — and wedge the kind, since the flag that says a start is in flight is cleared only by handling this. Handle already stops a watcher nobody wants, which is the right answer to a stale one; Epoch is here so a host can tell which project it belongs to, not so it can be discarded.

Jump to

Keyboard shortcuts

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