okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
508a12a
main
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 { 9Error ,Notice string 10Width ,Height ,Generation int 11Loading ,Saving bool 12} 13 14// newPageStatus starts a screen's first request under a new generation. 15func newPageStatus (loading bool )pageStatus { 16return 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 { 29if gen != p .Generation { 30return false 31 } 32* busy = false 33if err != nil { 34p .Error = err .Error () 35return false 36 } 37return true 38}