cat / 012
clone

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

main
012 / internal / ui / srcshapes_test.go
srcshapes_test.go 1.5K
1package ui23import (4 "os"5 "path/filepath"6 "sync"78 "src.rest/cat/012/internal/sheet"9 "src.rest/cat/012/internal/stress"10)1112// Linked sources for the speed gate (speed_test.go) and the stress13// benchmarks (srcstress_test.go): a model showing a source's tab, its14// jobs run as they come.1516// sourceModel is a model w x h showing the tab of the Parquet file at17// path linked as a source, opened, its first rows read.18func sourceModel(path string, w, h int) *Model {19 m := sized(sheet.New(), w, h)20 m.addSource(sheet.LinkSource{Path: path})21 settleSources(m)22 return m23}2425// settleSources runs what the sources have queued, and what that26// queues, until nothing is, reporting whether it settled.27func settleSources(m *Model) bool {28 for range 100 {29 run(m, m.syncSources())30 if r := m.sources(); r.host == nil || !r.host.Pending() && r.running == 0 && !m.pagesPending() {31 return true32 }33 }34 return false35}3637// pagesPending reports whether a view is being built.38func (m *Model) pagesPending() bool {39 for _, p := range m.src.pages {40 if p.Building() {41 return true42 }43 }44 return false45}4647// speedSources is the Parquet source of rows rows the speed gate48// links, made once in a folder of the system's temporary one.49var speedSources = sync.OnceValues(func() (string, error) {50 dir := filepath.Join(os.TempDir(), "012-speed-sources")51 if err := os.MkdirAll(dir, 0o755); err != nil {52 return "", err53 }54 return stress.SalesParquet(dir, speedSourceRows)55})5657// speedSourceRows is the rows of the speed gate's source.58const speedSourceRows = 200_000