aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-09-14 21:09:02 +0200
committerRobin Jarry <robin@jarry.cc>2022-09-14 22:11:33 +0200
commitee7937d0dd9201fdb78f363ddc8af950d0778f1b (patch)
tree33d827476be133aad84086b3d56b8b5ee0dbefd8
parentd93ad24f5f8f1f9204b5951abcb4691c9fd0b80f (diff)
downloadaerc-ee7937d0dd9201fdb78f363ddc8af950d0778f1b.tar.gz
ui: cleanup internals and api
Now that tcell events are handled in a goroutine, no need for a channel to buffer them. Rename ui.Tick() to ui.Render() and ui.Run() to ui.ProcessEvents() to better reflect what these functions do. Move screen.PollEvent() into ui.ProcessEvents(). Register the panic handler in ui.ProcessEvents(). Remove aerc.ui.Tick() from DecryptKeys(). What the hell was that? Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--aerc.go4
-rw-r--r--lib/ui/ui.go22
-rw-r--r--widgets/aerc.go15
3 files changed, 14 insertions, 27 deletions
diff --git a/aerc.go b/aerc.go
index 37d9509f..e1a1345b 100644
--- a/aerc.go
+++ b/aerc.go
@@ -241,12 +241,12 @@ func main() {
setWindowTitle()
}
- go ui.Run()
+ go ui.ProcessEvents()
for !ui.ShouldExit() {
for aerc.Tick() {
// Continue updating our internal state
}
- if !ui.Tick() {
+ if !ui.Render() {
// ~60 FPS
time.Sleep(16 * time.Millisecond)
}
diff --git a/lib/ui/ui.go b/lib/ui/ui.go
index 7cff5754..a4128a5c 100644
--- a/lib/ui/ui.go
+++ b/lib/ui/ui.go
@@ -13,9 +13,7 @@ type UI struct {
ctx *Context
screen tcell.Screen
popover *Popover
-
- tcEvents chan tcell.Event
- invalid int32 // access via atomic
+ invalid int32 // access via atomic
}
func Initialize(content DrawableInteractive) (*UI, error) {
@@ -36,19 +34,10 @@ func Initialize(content DrawableInteractive) (*UI, error) {
state := UI{
Content: content,
screen: screen,
-
- tcEvents: make(chan tcell.Event, 10),
}
state.ctx = NewContext(width, height, screen, state.onPopover)
state.exit.Store(false)
- go func() {
- defer logging.PanicHandler()
-
- for !state.ShouldExit() {
- state.tcEvents <- screen.PollEvent()
- }
- }()
state.invalid = 1
content.OnInvalidate(func(_ Drawable) {
@@ -82,7 +71,7 @@ func (state *UI) Close() {
state.screen.Fini()
}
-func (state *UI) Tick() bool {
+func (state *UI) Render() bool {
more := false
wasInvalid := atomic.SwapInt32(&state.invalid, 0)
@@ -110,8 +99,11 @@ func (state *UI) EnableMouse() {
state.screen.EnableMouse()
}
-func (state *UI) Run() {
- for event := range state.tcEvents {
+func (state *UI) ProcessEvents() {
+ defer logging.PanicHandler()
+
+ for !state.ShouldExit() {
+ event := state.screen.PollEvent()
if event, ok := event.(*tcell.EventResize); ok {
state.screen.Clear()
width, height := event.Size()
diff --git a/widgets/aerc.go b/widgets/aerc.go
index f0bc1ba7..cbc37795 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -743,18 +743,13 @@ func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err
fmt.Sprintf("Enter password for %s (%8X)\nPress <ESC> to cancel",
ident.Name, key.PublicKey.KeyId))
- for {
- select {
- case err = <-chErr:
- if err != nil {
- return nil, err
- }
- pass := <-chPass
- err = key.PrivateKey.Decrypt([]byte(pass))
+ for err := range chErr {
+ if err != nil {
return nil, err
- default:
- aerc.ui.Tick()
}
+ pass := <-chPass
+ err = key.PrivateKey.Decrypt([]byte(pass))
+ return nil, err
}
}
return nil, err