cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / live / live.go
live.go 1.8K
1// Package live reads the sources of linked regions as they change: a2// file followed as it grows or is rewritten (File), and anything else3// that yields a table's rows over time behind the same Source.4//5// A Source is polled on its owner's schedule, one poll at a time, from6// a goroutine of the owner's (a Bubble Tea command), and answers with an7// Update: rows to add, or all of them again, which the owner turns into8// a sheet.LiveOp for the region (Update.Op) and applies on the goroutine9// that owns the workbook. Sources never touch the workbook.10package live1112import (13 "context"14 "time"1516 "src.rest/cat/012/internal/sheet"17)1819// A Source yields a table's rows as they change.20type Source interface {21 // Poll looks once for what changed since the last poll. It reports22 // false when nothing did. Polls never overlap.23 Poll(ctx context.Context) (Update, bool)24 // Reload has the next poll read the table again, whole.25 Reload()26 // Close lets the source go; it is polled no more.27 Close()28}2930// Update is what a poll found.31type Update struct {32 // Reset has Rows replace every row; otherwise they follow the last.33 Reset bool34 // Header is the table's first row when it's new or changed.35 Header sheet.LiveRow36 Rows []sheet.LiveRow37 // Err says why the source can't be read, "" once it can.38 Err string39 // Note says what was left out or changed in reading.40 Note string41 // More is set when more is waiting to be read at once, rather than42 // after the next interval.43 More bool44 // At is when the poll found it.45 At time.Time46}4748// Op is u as the operation that applies it to the region named name.49func (u Update) Op(name string) sheet.LiveOp {50 return sheet.LiveOp{Region: name, At: u.At, Reset: u.Reset, Header: u.Header, Rows: u.Rows, Err: u.Err, Note: u.Note}51}5253// Interval is how often a followed source is polled.54const Interval = 250 * time.Millisecond