From ba24e92062f1a9b38065d503fd1dde749c27a56c Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 7 Oct 2022 11:00:31 -0500 Subject: [PATCH] invalidatable: cleanup dead code Remove invalidatable type and all associated calls. All items can directly invalidate the UI. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- commands/account/compose.go | 3 +- commands/account/next-result.go | 5 +-- commands/account/next.go | 5 +-- commands/account/recover.go | 3 +- commands/account/search.go | 3 +- commands/msg/archive.go | 3 +- commands/msg/delete.go | 3 +- commands/msg/forward.go | 3 +- commands/msg/invite.go | 3 +- commands/msg/recall.go | 3 +- commands/msg/reply.go | 3 +- commands/msg/toggle-threads.go | 3 +- commands/msg/unsubscribe.go | 3 +- commands/term.go | 3 +- lib/ui/borders.go | 8 +---- lib/ui/fill.go | 4 --- lib/ui/grid.go | 59 +++------------------------------ lib/ui/interfaces.go | 5 +-- lib/ui/invalidatable.go | 17 ---------- lib/ui/popover.go | 8 +---- lib/ui/stack.go | 25 ++------------ lib/ui/tab.go | 42 +++-------------------- lib/ui/text.go | 3 +- lib/ui/textinput.go | 5 +-- lib/ui/ui.go | 2 +- widgets/account-wizard.go | 15 +-------- widgets/account.go | 8 +---- widgets/aerc.go | 15 ++------- widgets/authinfo.go | 3 +- widgets/compose.go | 35 +++---------------- widgets/dirlist.go | 3 +- widgets/exline.go | 9 +---- widgets/getpasswd.go | 6 +--- widgets/listbox.go | 3 +- widgets/msglist.go | 6 +--- widgets/msgviewer.go | 31 +++-------------- widgets/pgpinfo.go | 3 +- widgets/selector.go | 9 ++--- widgets/spinner.go | 3 +- widgets/status.go | 3 +- widgets/terminal.go | 3 +- 41 files changed, 76 insertions(+), 303 deletions(-) delete mode 100644 lib/ui/invalidatable.go diff --git a/commands/account/compose.go b/commands/account/compose.go index fc7617e..16474b4 100644 --- a/commands/account/compose.go +++ b/commands/account/compose.go @@ -10,6 +10,7 @@ import ( "github.com/emersion/go-message/mail" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -64,7 +65,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) go func() { defer logging.PanicHandler() diff --git a/commands/account/next-result.go b/commands/account/next-result.go index daa7af3..922f95a 100644 --- a/commands/account/next-result.go +++ b/commands/account/next-result.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -34,13 +35,13 @@ func (NextPrevResult) Execute(aerc *widgets.Aerc, args []string) error { if store != nil { store.PrevResult() } - acct.Messages().Invalidate() + ui.Invalidate() } else { store := acct.Store() if store != nil { store.NextResult() } - acct.Messages().Invalidate() + ui.Invalidate() } return nil } diff --git a/commands/account/next.go b/commands/account/next.go index c9c2680..15dc536 100644 --- a/commands/account/next.go +++ b/commands/account/next.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -65,13 +66,13 @@ func ExecuteNextPrevMessage(args []string, acct *widgets.AccountView, pct bool, store := acct.Store() if store != nil { store.NextPrev(-n) - acct.Messages().Invalidate() + ui.Invalidate() } } else { store := acct.Store() if store != nil { store.NextPrev(n) - acct.Messages().Invalidate() + ui.Invalidate() } } return nil diff --git a/commands/account/recover.go b/commands/account/recover.go index 682a99c..b8acd26 100644 --- a/commands/account/recover.go +++ b/commands/account/recover.go @@ -8,6 +8,7 @@ import ( "path/filepath" "git.sr.ht/~rjarry/aerc/commands" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -110,7 +111,7 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error { tab := aerc.NewTab(composer, "Recovered") composer.OnHeaderChange("Subject", func(subject string) { tab.Name = subject - tab.Content.Invalidate() + ui.Invalidate() }) go func() { defer logging.PanicHandler() diff --git a/commands/account/search.go b/commands/account/search.go index 8209924..b4942bf 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -5,6 +5,7 @@ import ( "strings" "git.sr.ht/~rjarry/aerc/lib/statusline" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/worker/types" @@ -54,7 +55,7 @@ func (SearchFilter) Execute(aerc *widgets.Aerc, args []string) error { logging.Infof("Search results: %v", uids) store.ApplySearch(uids) // TODO: Remove when stores have multiple OnUpdate handlers - acct.Messages().Invalidate() + ui.Invalidate() } store.Search(args, cb) } diff --git a/commands/msg/archive.go b/commands/msg/archive.go index d485fd3..beba3a6 100644 --- a/commands/msg/archive.go +++ b/commands/msg/archive.go @@ -9,6 +9,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -117,7 +118,7 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error { if next == nil { aerc.RemoveTab(h.msgProvider) acct.Messages().Select(-1) - acct.Messages().Invalidate() + ui.Invalidate() return } lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(), diff --git a/commands/msg/delete.go b/commands/msg/delete.go index a3d024a..066476d 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -5,6 +5,7 @@ import ( "time" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/worker/types" @@ -60,7 +61,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { if next == nil { aerc.RemoveTab(h.msgProvider) acct.Messages().Select(-1) - acct.Messages().Invalidate() + ui.Invalidate() return } lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(), diff --git a/commands/msg/forward.go b/commands/msg/forward.go index 6f59a1b..4adfd12 100644 --- a/commands/msg/forward.go +++ b/commands/msg/forward.go @@ -14,6 +14,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/format" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -117,7 +118,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) return composer, nil } diff --git a/commands/msg/invite.go b/commands/msg/invite.go index 4e8d01d..37a194a 100644 --- a/commands/msg/invite.go +++ b/commands/msg/invite.go @@ -8,6 +8,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/calendar" "git.sr.ht/~rjarry/aerc/lib/format" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -167,7 +168,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) composer.OnClose(func(c *widgets.Composer) { diff --git a/commands/msg/recall.go b/commands/msg/recall.go index 52d4ee8..c5585b0 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -13,6 +13,7 @@ import ( "github.com/pkg/errors" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -93,7 +94,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) composer.OnClose(func(composer *widgets.Composer) { worker := composer.Worker() diff --git a/commands/msg/reply.go b/commands/msg/reply.go index e5f8d47..1baef83 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -13,6 +13,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/crypto" "git.sr.ht/~rjarry/aerc/lib/format" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -194,7 +195,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) composer.OnClose(func(c *widgets.Composer) { diff --git a/commands/msg/toggle-threads.go b/commands/msg/toggle-threads.go index af694bc..babdc31 100644 --- a/commands/msg/toggle-threads.go +++ b/commands/msg/toggle-threads.go @@ -4,6 +4,7 @@ import ( "errors" "git.sr.ht/~rjarry/aerc/lib/statusline" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -36,6 +37,6 @@ func (ToggleThreads) Execute(aerc *widgets.Aerc, args []string) error { } store.SetThreadedView(!store.ThreadedView()) acct.SetStatus(statusline.Threading(store.ThreadedView())) - acct.Messages().Invalidate() + ui.Invalidate() return nil } diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go index a9116e9..022135e 100644 --- a/commands/msg/unsubscribe.go +++ b/commands/msg/unsubscribe.go @@ -9,6 +9,7 @@ import ( "time" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -168,7 +169,7 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) composer.FocusTerminal() return nil diff --git a/commands/term.go b/commands/term.go index 924f71c..d6662fe 100644 --- a/commands/term.go +++ b/commands/term.go @@ -5,6 +5,7 @@ import ( "github.com/riywo/loginshell" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -41,7 +42,7 @@ func TermCore(aerc *widgets.Aerc, args []string) error { title = args[1] } tab.Name = title - tab.Content.Invalidate() + ui.Invalidate() } term.OnClose = func(err error) { aerc.RemoveTab(term) diff --git a/lib/ui/borders.go b/lib/ui/borders.go index 92e29b0..81d5db6 100644 --- a/lib/ui/borders.go +++ b/lib/ui/borders.go @@ -14,7 +14,6 @@ const ( ) type Bordered struct { - Invalidatable borders uint content Drawable uiConfig *config.UIConfig @@ -28,20 +27,15 @@ func NewBordered( content: content, uiConfig: uiConfig, } - content.OnInvalidate(b.contentInvalidated) return b } -func (bordered *Bordered) contentInvalidated(d Drawable) { - bordered.Invalidate() -} - func (bordered *Bordered) Children() []Drawable { return []Drawable{bordered.content} } func (bordered *Bordered) Invalidate() { - bordered.DoInvalidate(bordered) + Invalidate() } func (bordered *Bordered) Draw(ctx *Context) { diff --git a/lib/ui/fill.go b/lib/ui/fill.go index 13ad286..ff24890 100644 --- a/lib/ui/fill.go +++ b/lib/ui/fill.go @@ -21,10 +21,6 @@ func (f Fill) Draw(ctx *Context) { } } -func (f Fill) OnInvalidate(callback func(d Drawable)) { - // no-op -} - func (f Fill) Invalidate() { // no-op } diff --git a/lib/ui/grid.go b/lib/ui/grid.go index fe1d03e..76eba00 100644 --- a/lib/ui/grid.go +++ b/lib/ui/grid.go @@ -1,21 +1,17 @@ package ui import ( - "fmt" "math" "sync" - "sync/atomic" "github.com/gdamore/tcell/v2" ) type Grid struct { - Invalidatable rows []GridSpec rowLayout []gridLayout columns []GridSpec columnLayout []gridLayout - invalid bool // Protected by mutex cells []*GridCell @@ -51,11 +47,10 @@ type GridCell struct { RowSpan int ColSpan int Content Drawable - invalid atomic.Value // bool } func NewGrid() *Grid { - return &Grid{invalid: true} + return &Grid{} } // MakeGrid creates a grid with the specified number of columns and rows. Each @@ -95,19 +90,12 @@ func (grid *Grid) Columns(spec []GridSpec) *Grid { } func (grid *Grid) Draw(ctx *Context) { - invalid := grid.invalid - if invalid { - grid.reflow(ctx) - } + grid.reflow(ctx) grid.mutex.RLock() defer grid.mutex.RUnlock() for _, cell := range grid.cells { - cellInvalid := cell.invalid.Load().(bool) - if !cellInvalid && !invalid { - continue - } rows := grid.rowLayout[cell.Row : cell.Row+cell.RowSpan] cols := grid.columnLayout[cell.Column : cell.Column+cell.ColSpan] x := cols[0].Offset @@ -142,16 +130,11 @@ func (grid *Grid) Draw(ctx *Context) { func (grid *Grid) MouseEvent(localX int, localY int, event tcell.Event) { if event, ok := event.(*tcell.EventMouse); ok { - invalid := grid.invalid grid.mutex.RLock() defer grid.mutex.RUnlock() for _, cell := range grid.cells { - cellInvalid := cell.invalid.Load().(bool) - if !cellInvalid && !invalid { - continue - } rows := grid.rowLayout[cell.Row : cell.Row+cell.RowSpan] cols := grid.columnLayout[cell.Column : cell.Column+cell.ColSpan] x := cols[0].Offset @@ -220,23 +203,10 @@ func (grid *Grid) reflow(ctx *Context) { } flow(&grid.rows, &grid.rowLayout, ctx.Height()) flow(&grid.columns, &grid.columnLayout, ctx.Width()) - grid.invalid = false -} - -func (grid *Grid) invalidateLayout() { - grid.invalid = true - grid.DoInvalidate(grid) } func (grid *Grid) Invalidate() { - grid.invalidateLayout() - grid.mutex.RLock() - for _, cell := range grid.cells { - if cell.Content != nil { - cell.Content.Invalidate() - } - } - grid.mutex.RUnlock() + Invalidate() } func (grid *Grid) AddChild(content Drawable) *GridCell { @@ -248,9 +218,7 @@ func (grid *Grid) AddChild(content Drawable) *GridCell { grid.mutex.Lock() grid.cells = append(grid.cells, cell) grid.mutex.Unlock() - cell.Content.OnInvalidate(grid.cellInvalidated) - cell.invalid.Store(true) - grid.invalidateLayout() + grid.Invalidate() return cell } @@ -263,24 +231,7 @@ func (grid *Grid) RemoveChild(content Drawable) { } } grid.mutex.Unlock() - grid.invalidateLayout() -} - -func (grid *Grid) cellInvalidated(drawable Drawable) { - var cell *GridCell - grid.mutex.RLock() - for _, cell = range grid.cells { - if cell.Content == drawable { - break - } - cell = nil - } - grid.mutex.RUnlock() - if cell == nil { - panic(fmt.Errorf("Attempted to invalidate unknown cell")) - } - cell.invalid.Store(true) - grid.DoInvalidate(grid) + grid.Invalidate() } func Const(i int) func() int { diff --git a/lib/ui/interfaces.go b/lib/ui/interfaces.go index 8a62ecf..757f81c 100644 --- a/lib/ui/interfaces.go +++ b/lib/ui/interfaces.go @@ -12,10 +12,7 @@ type AercMsg interface{} type Drawable interface { // Called when this renderable should draw itself. Draw(ctx *Context) - // Specifies a function to call when this cell needs to be redrawn. The - // callback may be called in any goroutine. - OnInvalidate(callback func(d Drawable)) - // Invalidates the drawable. This can be called from any goroutine. + // Invalidates the UI. This can be called from any goroutine. Invalidate() } diff --git a/lib/ui/invalidatable.go b/lib/ui/invalidatable.go deleted file mode 100644 index fc354bd..0000000 --- a/lib/ui/invalidatable.go +++ /dev/null @@ -1,17 +0,0 @@ -package ui - -import ( - "sync/atomic" -) - -type Invalidatable struct { - onInvalidate atomic.Value -} - -func (i *Invalidatable) OnInvalidate(f func(d Drawable)) { - i.onInvalidate.Store(f) -} - -func (i *Invalidatable) DoInvalidate(d Drawable) { - atomic.StoreInt32(&dirty, DIRTY) -} diff --git a/lib/ui/popover.go b/lib/ui/popover.go index 8c8c4cd..9cc491d 100644 --- a/lib/ui/popover.go +++ b/lib/ui/popover.go @@ -53,11 +53,5 @@ func (p *Popover) Focus(f bool) { } func (p *Popover) Invalidate() { - p.content.Invalidate() -} - -func (p *Popover) OnInvalidate(f func(Drawable)) { - p.content.OnInvalidate(func(_ Drawable) { - f(p) - }) + Invalidate() } diff --git a/lib/ui/stack.go b/lib/ui/stack.go index 5ccf13b..c0aca4e 100644 --- a/lib/ui/stack.go +++ b/lib/ui/stack.go @@ -9,9 +9,8 @@ import ( ) type Stack struct { - children []Drawable - onInvalidate []func(d Drawable) - uiConfig config.UIConfig + children []Drawable + uiConfig config.UIConfig } func NewStack(uiConfig config.UIConfig) *Stack { @@ -22,14 +21,8 @@ func (stack *Stack) Children() []Drawable { return stack.children } -func (stack *Stack) OnInvalidate(onInvalidate func(d Drawable)) { - stack.onInvalidate = append(stack.onInvalidate, onInvalidate) -} - func (stack *Stack) Invalidate() { - for _, fn := range stack.onInvalidate { - fn(stack) - } + Invalidate() } func (stack *Stack) Draw(ctx *Context) { @@ -50,11 +43,7 @@ func (stack *Stack) MouseEvent(localX int, localY int, event tcell.Event) { } func (stack *Stack) Push(d Drawable) { - if len(stack.children) != 0 { - stack.Peek().OnInvalidate(nil) - } stack.children = append(stack.children, d) - d.OnInvalidate(stack.invalidateFromChild) stack.Invalidate() } @@ -65,10 +54,6 @@ func (stack *Stack) Pop() Drawable { d := stack.children[len(stack.children)-1] stack.children = stack.children[:len(stack.children)-1] stack.Invalidate() - d.OnInvalidate(nil) - if len(stack.children) != 0 { - stack.Peek().OnInvalidate(stack.invalidateFromChild) - } return d } @@ -78,7 +63,3 @@ func (stack *Stack) Peek() Drawable { } return stack.children[len(stack.children)-1] } - -func (stack *Stack) invalidateFromChild(d Drawable) { - stack.Invalidate() -} diff --git a/lib/ui/tab.go b/lib/ui/tab.go index df76ccc..d4841ef 100644 --- a/lib/ui/tab.go +++ b/lib/ui/tab.go @@ -20,9 +20,6 @@ type Tabs struct { uiConfig *config.UIConfig - onInvalidateStrip func(d Drawable) //nolint:structcheck // used within this file - onInvalidateContent func(d Drawable) - parent *Tabs //nolint:structcheck // used within this file CloseTab func(index int) } @@ -59,7 +56,6 @@ func (tabs *Tabs) Add(content Drawable, name string, uiConf *config.UIConfig) *T } tabs.tabs = append(tabs.tabs, tab) tabs.selectPriv(len(tabs.tabs) - 1) - content.OnInvalidate(tabs.invalidateChild) return tab } @@ -73,18 +69,6 @@ func (tabs *Tabs) Names() []string { return names } -func (tabs *Tabs) invalidateChild(d Drawable) { - if tabs.curIndex >= len(tabs.tabs) { - return - } - - if tabs.tabs[tabs.curIndex].Content == d { - if tabs.onInvalidateContent != nil { - tabs.onInvalidateContent(tabs.TabContent) - } - } -} - func (tabs *Tabs) Remove(content Drawable) { tabs.m.Lock() defer tabs.m.Unlock() @@ -133,8 +117,7 @@ func (tabs *Tabs) Replace(contentSrc Drawable, contentTarget Drawable, name stri break } } - tabs.TabStrip.Invalidate() - contentTarget.OnInvalidate(tabs.invalidateChild) + Invalidate() } func (tabs *Tabs) Get(index int) *Tab { @@ -172,8 +155,7 @@ func (tabs *Tabs) selectPriv(index int) bool { tabs.pushHistory(tabs.curIndex) } tabs.curIndex = index - tabs.TabStrip.Invalidate() - tabs.TabContent.Invalidate() + Invalidate() } return true } @@ -246,7 +228,7 @@ func (tabs *Tabs) moveTabPriv(to int, relative bool) { tabs.tabs[to] = tab tabs.curIndex = to - tabs.TabStrip.Invalidate() + Invalidate() } func (tabs *Tabs) PinTab() { @@ -384,9 +366,7 @@ func (strip *TabStrip) Draw(ctx *Context) { } func (strip *TabStrip) Invalidate() { - if strip.onInvalidateStrip != nil { - strip.onInvalidateStrip(strip) - } + Invalidate() } func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { @@ -440,10 +420,6 @@ func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { } } -func (strip *TabStrip) OnInvalidate(onInvalidate func(d Drawable)) { - strip.onInvalidateStrip = onInvalidate -} - func (strip *TabStrip) clicked(mouseX int, mouseY int) (int, bool) { x := 0 for i, tab := range strip.tabs { @@ -490,13 +466,5 @@ func (content *TabContent) MouseEvent(localX int, localY int, event tcell.Event) } func (content *TabContent) Invalidate() { - if content.onInvalidateContent != nil { - content.onInvalidateContent(content) - } - tab := content.tabs[content.curIndex] - tab.Content.Invalidate() -} - -func (content *TabContent) OnInvalidate(onInvalidate func(d Drawable)) { - content.onInvalidateContent = onInvalidate + Invalidate() } diff --git a/lib/ui/text.go b/lib/ui/text.go index ffae193..def61a0 100644 --- a/lib/ui/text.go +++ b/lib/ui/text.go @@ -12,7 +12,6 @@ const ( ) type Text struct { - Invalidatable text string strategy uint style tcell.Style @@ -51,5 +50,5 @@ func (t *Text) Draw(ctx *Context) { } func (t *Text) Invalidate() { - t.DoInvalidate(t) + Invalidate() } diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index d99871c..2a8b7c7 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -17,7 +17,6 @@ import ( // TODO: scrolling type TextInput struct { - Invalidatable sync.Mutex cells int ctx *Context @@ -90,7 +89,7 @@ func (ti *TextInput) Set(value string) *TextInput { } func (ti *TextInput) Invalidate() { - ti.DoInvalidate(ti) + Invalidate() } func (ti *TextInput) Draw(ctx *Context) { @@ -530,5 +529,3 @@ func findStem(words []string) string { func (c *completions) Focus(_ bool) {} func (c *completions) Invalidate() {} - -func (c *completions) OnInvalidate(_ func(Drawable)) {} diff --git a/lib/ui/ui.go b/lib/ui/ui.go index 073684c..313f90d 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -122,7 +122,7 @@ func (state *UI) HandleEvent(event tcell.Event) { state.screen.Clear() width, height := event.Size() state.ctx = NewContext(width, height, state.screen, state.onPopover) - state.Content.Invalidate() + Invalidate() } // if we have a popover, and it can handle the event, it does so if state.popover == nil || !state.popover.Event(event) { diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 4856c60..b6e0a5e 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -40,7 +40,6 @@ const ( ) type AccountWizard struct { - ui.Invalidatable aerc *Aerc conf *config.AercConfig step int @@ -224,9 +223,6 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { wizard.basics = []ui.Interactive{ wizard.accountName, wizard.fullName, wizard.email, selector, } - basics.OnInvalidate(func(_ ui.Drawable) { - wizard.Invalidate() - }) incoming := ui.NewGrid().Rows([]ui.GridSpec{ {Strategy: ui.SIZE_EXACT, Size: ui.Const(3)}, // Introduction @@ -303,9 +299,6 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { wizard.imapUsername, wizard.imapPassword, wizard.imapServer, imapMode, selector, } - incoming.OnInvalidate(func(_ ui.Drawable) { - wizard.Invalidate() - }) outgoing := ui.NewGrid().Rows([]ui.GridSpec{ {Strategy: ui.SIZE_EXACT, Size: ui.Const(3)}, // Introduction @@ -399,9 +392,6 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { wizard.smtpUsername, wizard.smtpPassword, wizard.smtpServer, smtpMode, copySent, selector, } - outgoing.OnInvalidate(func(_ ui.Drawable) { - wizard.Invalidate() - }) complete := ui.NewGrid().Rows([]ui.GridSpec{ {Strategy: ui.SIZE_EXACT, Size: ui.Const(7)}, // Introduction @@ -431,9 +421,6 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { }) complete.AddChild(selector).At(1, 0) wizard.complete = []ui.Interactive{selector} - complete.OnInvalidate(func(_ ui.Drawable) { - wizard.Invalidate() - }) wizard.steps = []*ui.Grid{basics, incoming, outgoing, complete} return wizard @@ -665,7 +652,7 @@ func (wizard *AccountWizard) smtpUri() url.URL { } func (wizard *AccountWizard) Invalidate() { - wizard.DoInvalidate(wizard) + ui.Invalidate() } func (wizard *AccountWizard) Draw(ctx *ui.Context) { diff --git a/widgets/account.go b/widgets/account.go index 93a7597..cafc29d 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -143,14 +143,8 @@ func (acct *AccountView) Name() string { return acct.acct.Name } -func (acct *AccountView) OnInvalidate(onInvalidate func(d ui.Drawable)) { - acct.grid.OnInvalidate(func(_ ui.Drawable) { - onInvalidate(acct) - }) -} - func (acct *AccountView) Invalidate() { - acct.grid.Invalidate() + ui.Invalidate() } func (acct *AccountView) Draw(ctx *ui.Context) { diff --git a/widgets/aerc.go b/widgets/aerc.go index b396cf5..5697277 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -152,14 +152,8 @@ func (aerc *Aerc) HandleMessage(msg types.WorkerMessage) { } } -func (aerc *Aerc) OnInvalidate(onInvalidate func(d ui.Drawable)) { - aerc.grid.OnInvalidate(func(_ ui.Drawable) { - onInvalidate(aerc) - }) -} - func (aerc *Aerc) Invalidate() { - aerc.grid.Invalidate() + ui.Invalidate() } func (aerc *Aerc) Focus(focus bool) { @@ -304,7 +298,7 @@ func (aerc *Aerc) Event(event tcell.Event) bool { Key: event.Key(), Rune: event.Rune(), }) - aerc.statusline.Invalidate() + ui.Invalidate() bindings := aerc.getBindings() incomplete := false result, strokes := bindings.GetBinding(aerc.pendingKeys) @@ -724,7 +718,7 @@ func (aerc *Aerc) Mailto(addr *url.URL) error { } else { tab.Name = subject } - tab.Content.Invalidate() + ui.Invalidate() }) return nil } @@ -775,9 +769,6 @@ func (aerc *Aerc) CloseBackends() error { func (aerc *Aerc) AddDialog(d ui.DrawableInteractive) { aerc.dialog = d - aerc.dialog.OnInvalidate(func(_ ui.Drawable) { - aerc.Invalidate() - }) aerc.Invalidate() } diff --git a/widgets/authinfo.go b/widgets/authinfo.go index a57d8a1..2b406a7 100644 --- a/widgets/authinfo.go +++ b/widgets/authinfo.go @@ -11,7 +11,6 @@ import ( ) type AuthInfo struct { - ui.Invalidatable authdetails *auth.Details showInfo bool uiConfig *config.UIConfig @@ -85,5 +84,5 @@ func (a *AuthInfo) Draw(ctx *ui.Context) { } func (a *AuthInfo) Invalidate() { - a.DoInvalidate(a) + ui.Invalidate() } diff --git a/widgets/compose.go b/widgets/compose.go index 9b8b30c..0645223 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -127,7 +127,6 @@ func (c *Composer) SwitchAccount(newAcct *AccountView) error { editor.loadValue() } c.Invalidate() - c.aerc.Invalidate() logging.Infof("account sucessfully switched") return nil } @@ -567,13 +566,7 @@ func (c *Composer) Draw(ctx *ui.Context) { } func (c *Composer) Invalidate() { - c.grid.Invalidate() -} - -func (c *Composer) OnInvalidate(fn func(d ui.Drawable)) { - c.grid.OnInvalidate(func(_ ui.Drawable) { - fn(c) - }) + ui.Invalidate() } func (c *Composer) Close() { @@ -1107,7 +1100,7 @@ func extractHumanHeaderValue(key string, h *mail.Header) string { // decoding issues are ignored and return their raw values func (he *headerEditor) loadValue() { he.input.Set(extractHumanHeaderValue(he.name, he.header)) - he.input.Invalidate() + ui.Invalidate() } // storeValue writes the current state back to the underlying header. @@ -1159,13 +1152,7 @@ func (he *headerEditor) MouseEvent(localX int, localY int, event tcell.Event) { } func (he *headerEditor) Invalidate() { - he.input.Invalidate() -} - -func (he *headerEditor) OnInvalidate(fn func(ui.Drawable)) { - he.input.OnInvalidate(func(_ ui.Drawable) { - fn(he) - }) + ui.Invalidate() } func (he *headerEditor) Focus(focused bool) { @@ -1301,13 +1288,7 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage { } func (rm *reviewMessage) Invalidate() { - rm.grid.Invalidate() -} - -func (rm *reviewMessage) OnInvalidate(fn func(ui.Drawable)) { - rm.grid.OnInvalidate(func(_ ui.Drawable) { - fn(rm) - }) + ui.Invalidate() } func (rm *reviewMessage) Draw(ctx *ui.Context) { @@ -1344,13 +1325,7 @@ func (cs *cryptoStatus) Draw(ctx *ui.Context) { } func (cs *cryptoStatus) Invalidate() { - cs.status.Invalidate() -} - -func (cs *cryptoStatus) OnInvalidate(fn func(ui.Drawable)) { - cs.status.OnInvalidate(func(_ ui.Drawable) { - fn(cs) - }) + ui.Invalidate() } func (c *Composer) checkEncryptionKeys(_ string) bool { diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 0f86a08..7055039 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -48,7 +48,6 @@ type DirectoryLister interface { } type DirectoryList struct { - ui.Invalidatable sync.Mutex Scrollable aercConf *config.AercConfig @@ -199,7 +198,7 @@ func (dirlist *DirectoryList) Selected() string { } func (dirlist *DirectoryList) Invalidate() { - dirlist.DoInvalidate(dirlist) + ui.Invalidate() } func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen func() string) string { diff --git a/widgets/exline.go b/widgets/exline.go index 8d3c7ca..789ccde 100644 --- a/widgets/exline.go +++ b/widgets/exline.go @@ -9,7 +9,6 @@ import ( ) type ExLine struct { - ui.Invalidatable commit func(cmd string) finish func() tabcomplete func(cmd string) ([]string, string) @@ -34,9 +33,6 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin input: input, conf: conf, } - input.OnInvalidate(func(d ui.Drawable) { - exline.Invalidate() - }) return exline } @@ -57,14 +53,11 @@ func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string), cmdHistory: &nullHistory{input: input}, input: input, } - input.OnInvalidate(func(d ui.Drawable) { - exline.Invalidate() - }) return exline } func (ex *ExLine) Invalidate() { - ex.DoInvalidate(ex) + ui.Invalidate() } func (ex *ExLine) Draw(ctx *ui.Context) { diff --git a/widgets/getpasswd.go b/widgets/getpasswd.go index e6de75e..70a2648 100644 --- a/widgets/getpasswd.go +++ b/widgets/getpasswd.go @@ -10,7 +10,6 @@ import ( ) type GetPasswd struct { - ui.Invalidatable callback func(string, error) title string prompt string @@ -28,9 +27,6 @@ func NewGetPasswd(title string, prompt string, conf *config.AercConfig, conf: conf, input: ui.NewTextInput("", &conf.Ui).Password(true).Prompt("Password: "), } - getpasswd.input.OnInvalidate(func(_ ui.Drawable) { - getpasswd.Invalidate() - }) getpasswd.input.Focus(true) return getpasswd } @@ -47,7 +43,7 @@ func (gp *GetPasswd) Draw(ctx *ui.Context) { } func (gp *GetPasswd) Invalidate() { - gp.DoInvalidate(gp) + ui.Invalidate() } func (gp *GetPasswd) Event(event tcell.Event) bool { diff --git a/widgets/listbox.go b/widgets/listbox.go index 2723ae3..d1f1b25 100644 --- a/widgets/listbox.go +++ b/widgets/listbox.go @@ -13,7 +13,6 @@ import ( type ListBox struct { Scrollable - ui.Invalidatable title string lines []string selected string @@ -186,7 +185,7 @@ func (lb *ListBox) drawScrollbar(ctx *ui.Context) { } func (lb *ListBox) Invalidate() { - lb.DoInvalidate(lb) + ui.Invalidate() } func (lb *ListBox) Event(event tcell.Event) bool { diff --git a/widgets/msglist.go b/widgets/msglist.go index 74308cc..7857a3d 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -19,7 +19,6 @@ import ( ) type MessageList struct { - ui.Invalidatable Scrollable conf *config.AercConfig height int @@ -37,16 +36,13 @@ func NewMessageList(conf *config.AercConfig, aerc *Aerc) *MessageList { isInitalizing: true, aerc: aerc, } - ml.spinner.OnInvalidate(func(_ ui.Drawable) { - ml.Invalidate() - }) // TODO: stop spinner, probably ml.spinner.Start() return ml } func (ml *MessageList) Invalidate() { - ml.DoInvalidate(ml) + ui.Invalidate() } func (ml *MessageList) Draw(ctx *ui.Context) { diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 126bf85..8904758 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -30,7 +30,6 @@ var ansi = regexp.MustCompile("\x1B\\[[0-?]*[ -/]*[@-~]") var _ ProvidesMessages = (*MessageViewer)(nil) type MessageViewer struct { - ui.Invalidatable acct *AccountView conf *config.AercConfig err error @@ -41,7 +40,6 @@ type MessageViewer struct { } type PartSwitcher struct { - ui.Invalidatable parts []*PartViewer selected int showHeaders bool @@ -219,9 +217,6 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher, return err } switcher.parts = []*PartViewer{pv} - pv.OnInvalidate(func(_ ui.Drawable) { - switcher.Invalidate() - }) } else { switcher.parts, err = enumerateParts(acct, conf, msg, msg.BodyStructure(), []int{}) @@ -231,9 +226,6 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher, selectedPriority := -1 logging.Infof("Selecting best message from %v", conf.Viewer.Alternatives) for i, pv := range switcher.parts { - pv.OnInvalidate(func(_ ui.Drawable) { - switcher.Invalidate() - }) // Switch to user's preferred mimetype if switcher.selected == -1 && pv.part.MIMEType != "multipart" { switcher.selected = i @@ -273,13 +265,7 @@ func (mv *MessageViewer) MouseEvent(localX int, localY int, event tcell.Event) { } func (mv *MessageViewer) Invalidate() { - mv.grid.Invalidate() -} - -func (mv *MessageViewer) OnInvalidate(fn func(d ui.Drawable)) { - mv.grid.OnInvalidate(func(_ ui.Drawable) { - fn(mv) - }) + ui.Invalidate() } func (mv *MessageViewer) Store() *lib.MessageStore { @@ -408,7 +394,7 @@ func (mv *MessageViewer) UpdateScreen() { } func (ps *PartSwitcher) Invalidate() { - ps.DoInvalidate(ps) + ui.Invalidate() } func (ps *PartSwitcher) Focus(focus bool) { @@ -521,7 +507,6 @@ func (mv *MessageViewer) Focus(focus bool) { } type PartViewer struct { - ui.Invalidatable conf *config.AercConfig acctConfig *config.AccountConfig err error @@ -630,9 +615,6 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig, term.OnStart = func() { pv.attemptCopy() } - term.OnInvalidate(func(_ ui.Drawable) { - pv.Invalidate() - }) } return pv, nil @@ -644,9 +626,7 @@ func (pv *PartViewer) SetSource(reader io.Reader) { } func (pv *PartViewer) UpdateScreen() { - if pv.term != nil { - pv.term.Invalidate() - } + pv.Invalidate() } func (pv *PartViewer) attemptCopy() { @@ -840,7 +820,7 @@ What would you like to do?`, pv.part.MIMEType, pv.part.MIMESubType) } func (pv *PartViewer) Invalidate() { - pv.DoInvalidate(pv) + ui.Invalidate() } func (pv *PartViewer) Draw(ctx *ui.Context) { @@ -878,7 +858,6 @@ func (pv *PartViewer) Event(event tcell.Event) bool { } type HeaderView struct { - ui.Invalidatable conf *config.AercConfig Name string Value string @@ -913,5 +892,5 @@ func (hv *HeaderView) Draw(ctx *ui.Context) { } func (hv *HeaderView) Invalidate() { - hv.DoInvalidate(hv) + ui.Invalidate() } diff --git a/widgets/pgpinfo.go b/widgets/pgpinfo.go index ee2a026..c64bcfd 100644 --- a/widgets/pgpinfo.go +++ b/widgets/pgpinfo.go @@ -12,7 +12,6 @@ import ( ) type PGPInfo struct { - ui.Invalidatable details *models.MessageDetails uiConfig *config.UIConfig } @@ -95,5 +94,5 @@ func (p *PGPInfo) Draw(ctx *ui.Context) { } func (p *PGPInfo) Invalidate() { - p.DoInvalidate(p) + ui.Invalidate() } diff --git a/widgets/selector.go b/widgets/selector.go index 8a1a162..66dfb8b 100644 --- a/widgets/selector.go +++ b/widgets/selector.go @@ -11,7 +11,6 @@ import ( ) type Selector struct { - ui.Invalidatable chooser bool focused bool focus int @@ -36,7 +35,7 @@ func (sel *Selector) Chooser(chooser bool) *Selector { } func (sel *Selector) Invalidate() { - sel.DoInvalidate(sel) + ui.Invalidate() } func (sel *Selector) Draw(ctx *ui.Context) { @@ -166,7 +165,6 @@ func (sel *Selector) Event(event tcell.Event) bool { var ErrNoOptionSelected = fmt.Errorf("no option selected") type SelectorDialog struct { - ui.Invalidatable callback func(string, error) title string prompt string @@ -184,9 +182,6 @@ func NewSelectorDialog(title string, prompt string, options []string, focus int, uiConfig: uiConfig, selector: NewSelector(options, focus, uiConfig).Chooser(true), } - sd.selector.OnInvalidate(func(_ ui.Drawable) { - sd.Invalidate() - }) sd.selector.Focus(true) return sd } @@ -203,7 +198,7 @@ func (gp *SelectorDialog) Draw(ctx *ui.Context) { } func (gp *SelectorDialog) Invalidate() { - gp.DoInvalidate(gp) + ui.Invalidate() } func (gp *SelectorDialog) Event(event tcell.Event) bool { diff --git a/widgets/spinner.go b/widgets/spinner.go index 0e7c900..34c3d82 100644 --- a/widgets/spinner.go +++ b/widgets/spinner.go @@ -13,7 +13,6 @@ import ( ) type Spinner struct { - ui.Invalidatable frame int64 // access via atomic frames []string stop chan struct{} @@ -82,5 +81,5 @@ func (s *Spinner) Draw(ctx *ui.Context) { } func (s *Spinner) Invalidate() { - s.DoInvalidate(s) + ui.Invalidate() } diff --git a/widgets/status.go b/widgets/status.go index c5559d3..d8d0328 100644 --- a/widgets/status.go +++ b/widgets/status.go @@ -12,7 +12,6 @@ import ( ) type StatusLine struct { - ui.Invalidatable stack []*StatusMessage fallback StatusMessage aerc *Aerc @@ -33,7 +32,7 @@ func NewStatusLine(uiConfig config.UIConfig) *StatusLine { } func (status *StatusLine) Invalidate() { - status.DoInvalidate(status) + ui.Invalidate() } func (status *StatusLine) Draw(ctx *ui.Context) { diff --git a/widgets/terminal.go b/widgets/terminal.go index 39cd9f2..e0a76ca 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -13,7 +13,6 @@ import ( ) type Terminal struct { - ui.Invalidatable closed bool cmd *exec.Cmd ctx *ui.Context @@ -71,7 +70,7 @@ func (term *Terminal) Destroy() { } func (term *Terminal) Invalidate() { - term.DoInvalidate(term) + ui.Invalidate() } func (term *Terminal) Draw(ctx *ui.Context) {