events: introduce AercMsg and QueueRedraw

Add AercMsg as a main interface for internal communication in aerc in
preparation for a main event loop. Add a QueueRedraw function to to
trigger a redraw. This will be needed for widgets which should be drawn
after some delay (completions, terminal, for example)

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-10-06 11:46:40 -05:00 committed by Robin Jarry
parent c6561d32a8
commit d847073bdf
2 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,9 @@ import (
"github.com/gdamore/tcell/v2"
)
// AercMsg is used to communicate within aerc
type AercMsg interface{}
// Drawable is a UI component that can draw. Unless specified, all methods must
// only be called from a single goroutine, the UI goroutine.
type Drawable interface {

View File

@ -7,6 +7,14 @@ import (
"github.com/gdamore/tcell/v2"
)
var MsgChannel = make(chan AercMsg, 50)
// QueueRedraw sends a nil message into the MsgChannel. Nothing will handle this
// message, but a redraw will occur if the UI is marked as invalid
func QueueRedraw() {
MsgChannel <- nil
}
type UI struct {
Content DrawableInteractive
exit atomic.Value // bool