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>
This commit is contained in:
parent
d93ad24f5f
commit
ee7937d0dd
3 changed files with 14 additions and 27 deletions
4
aerc.go
4
aerc.go
|
@ -241,12 +241,12 @@ func main() {
|
||||||
setWindowTitle()
|
setWindowTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
go ui.Run()
|
go ui.ProcessEvents()
|
||||||
for !ui.ShouldExit() {
|
for !ui.ShouldExit() {
|
||||||
for aerc.Tick() {
|
for aerc.Tick() {
|
||||||
// Continue updating our internal state
|
// Continue updating our internal state
|
||||||
}
|
}
|
||||||
if !ui.Tick() {
|
if !ui.Render() {
|
||||||
// ~60 FPS
|
// ~60 FPS
|
||||||
time.Sleep(16 * time.Millisecond)
|
time.Sleep(16 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
20
lib/ui/ui.go
20
lib/ui/ui.go
|
@ -13,8 +13,6 @@ type UI struct {
|
||||||
ctx *Context
|
ctx *Context
|
||||||
screen tcell.Screen
|
screen tcell.Screen
|
||||||
popover *Popover
|
popover *Popover
|
||||||
|
|
||||||
tcEvents chan tcell.Event
|
|
||||||
invalid int32 // access via atomic
|
invalid int32 // access via atomic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,19 +34,10 @@ func Initialize(content DrawableInteractive) (*UI, error) {
|
||||||
state := UI{
|
state := UI{
|
||||||
Content: content,
|
Content: content,
|
||||||
screen: screen,
|
screen: screen,
|
||||||
|
|
||||||
tcEvents: make(chan tcell.Event, 10),
|
|
||||||
}
|
}
|
||||||
state.ctx = NewContext(width, height, screen, state.onPopover)
|
state.ctx = NewContext(width, height, screen, state.onPopover)
|
||||||
|
|
||||||
state.exit.Store(false)
|
state.exit.Store(false)
|
||||||
go func() {
|
|
||||||
defer logging.PanicHandler()
|
|
||||||
|
|
||||||
for !state.ShouldExit() {
|
|
||||||
state.tcEvents <- screen.PollEvent()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
state.invalid = 1
|
state.invalid = 1
|
||||||
content.OnInvalidate(func(_ Drawable) {
|
content.OnInvalidate(func(_ Drawable) {
|
||||||
|
@ -82,7 +71,7 @@ func (state *UI) Close() {
|
||||||
state.screen.Fini()
|
state.screen.Fini()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *UI) Tick() bool {
|
func (state *UI) Render() bool {
|
||||||
more := false
|
more := false
|
||||||
|
|
||||||
wasInvalid := atomic.SwapInt32(&state.invalid, 0)
|
wasInvalid := atomic.SwapInt32(&state.invalid, 0)
|
||||||
|
@ -110,8 +99,11 @@ func (state *UI) EnableMouse() {
|
||||||
state.screen.EnableMouse()
|
state.screen.EnableMouse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *UI) Run() {
|
func (state *UI) ProcessEvents() {
|
||||||
for event := range state.tcEvents {
|
defer logging.PanicHandler()
|
||||||
|
|
||||||
|
for !state.ShouldExit() {
|
||||||
|
event := state.screen.PollEvent()
|
||||||
if event, ok := event.(*tcell.EventResize); ok {
|
if event, ok := event.(*tcell.EventResize); ok {
|
||||||
state.screen.Clear()
|
state.screen.Clear()
|
||||||
width, height := event.Size()
|
width, height := event.Size()
|
||||||
|
|
|
@ -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",
|
fmt.Sprintf("Enter password for %s (%8X)\nPress <ESC> to cancel",
|
||||||
ident.Name, key.PublicKey.KeyId))
|
ident.Name, key.PublicKey.KeyId))
|
||||||
|
|
||||||
for {
|
for err := range chErr {
|
||||||
select {
|
|
||||||
case err = <-chErr:
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pass := <-chPass
|
pass := <-chPass
|
||||||
err = key.PrivateKey.Decrypt([]byte(pass))
|
err = key.PrivateKey.Decrypt([]byte(pass))
|
||||||
return nil, err
|
return nil, err
|
||||||
default:
|
|
||||||
aerc.ui.Tick()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue