okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

dawntui: delete the old page helpers and inkWrap that no screen uses508a12a

main
1.1 KiB38 linesraw
1package tui
2
3import "sync/atomic"
4
5// pageStatus is the state every screen shares: the terminal size, the load
6// or save in flight, and the last error and notice. Every request carries
7// the Generation it was started under; a reply under any other is stale.
8type pageStatus struct {
9	Error, Notice             string
10	Width, Height, Generation int
11	Loading, Saving           bool
12}
13
14// newPageStatus starts a screen's first request under a new generation.
15func newPageStatus(loading bool) pageStatus {
16	return pageStatus{Loading: loading, Generation: nextPageGeneration()}
17}
18
19// Commands outlive closed screens; unique generations reject their replies.
20var pageGeneration atomic.Int64
21
22func nextPageGeneration() int { return int(pageGeneration.Add(1)) }
23
24func (p *pageStatus) SetSize(width, height int) { p.Width, p.Height = width, height }
25
26// settle takes a reply for the request busy tracks: false when it is stale
27// or failed, with the failure shown.
28func (p *pageStatus) settle(gen int, err error, busy *bool) bool {
29	if gen != p.Generation {
30		return false
31	}
32	*busy = false
33	if err != nil {
34		p.Error = err.Error()
35		return false
36	}
37	return true
38}