aboutsummaryrefslogtreecommitdiff
path: root/lib/ui/ui.go
diff options
context:
space:
mode:
authorMarkus Ongyerth <aerc@ongy.net>2018-06-01 09:58:00 +0200
committerDrew DeVault <sir@cmpwn.com>2018-06-01 16:04:43 -0700
commit80e891a8024ac10a60daa790131e04f0326b0c73 (patch)
tree7a07cc26b2885e43e57e1672d2895c7fae2b173e /lib/ui/ui.go
parent3836d240c9aa26615e7d768a57436d171edc3831 (diff)
switch to tcell from termbox
This is a simple mostly straight forward switch to tcell in favor of termbox. It uses the tcell native api (not the compat layer) but does not make use of most features. Further changes should include moving to tcell's views.TextArea and the general built in widget behaviour instead of the current ad hoc implementation. Regression: Cursor isn't shown in ex-line
Diffstat (limited to 'lib/ui/ui.go')
-rw-r--r--lib/ui/ui.go48
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/ui/ui.go b/lib/ui/ui.go
index e9b4e9b..d3eacf2 100644
--- a/lib/ui/ui.go
+++ b/lib/ui/ui.go
@@ -1,7 +1,7 @@
package ui
import (
- tb "github.com/nsf/termbox-go"
+ "github.com/gdamore/tcell"
"git.sr.ht/~sircmpwn/aerc2/config"
)
@@ -10,30 +10,41 @@ type UI struct {
Exit bool
Content DrawableInteractive
ctx *Context
+ screen tcell.Screen
- tbEvents chan tb.Event
+ tcEvents chan tcell.Event
invalidations chan interface{}
}
func Initialize(conf *config.AercConfig,
content DrawableInteractive) (*UI, error) {
- if err := tb.Init(); err != nil {
+ screen, err := tcell.NewScreen()
+ if err != nil {
return nil, err
}
- width, height := tb.Size()
+
+ if err = screen.Init(); err != nil {
+ return nil, err
+ }
+
+ screen.Clear()
+ screen.HideCursor()
+
+ width, height := screen.Size()
+
state := UI{
Content: content,
- ctx: NewContext(width, height),
+ ctx: NewContext(width, height, screen),
+ screen: screen,
- tbEvents: make(chan tb.Event, 10),
+ tcEvents: make(chan tcell.Event, 10),
invalidations: make(chan interface{}),
}
- tb.SetInputMode(tb.InputEsc | tb.InputMouse)
- tb.SetOutputMode(tb.Output256)
+ //tb.SetOutputMode(tb.Output256)
go (func() {
for !state.Exit {
- state.tbEvents <- tb.PollEvent()
+ state.tcEvents <- screen.PollEvent()
}
})()
go (func() { state.invalidations <- nil })()
@@ -44,27 +55,28 @@ func Initialize(conf *config.AercConfig,
}
func (state *UI) Close() {
- tb.Close()
+ state.screen.Fini()
}
func (state *UI) Tick() bool {
select {
- case event := <-state.tbEvents:
- switch event.Type {
- case tb.EventKey:
+ case event := <-state.tcEvents:
+ switch event := event.(type) {
+ case *tcell.EventKey:
// TODO: temporary
- if event.Key == tb.KeyEsc {
+ if event.Key() == tcell.KeyEsc {
state.Exit = true
}
- case tb.EventResize:
- tb.Clear(tb.ColorDefault, tb.ColorDefault)
- state.ctx = NewContext(event.Width, event.Height)
+ case *tcell.EventResize:
+ state.screen.Clear()
+ width, height := event.Size()
+ state.ctx = NewContext(width, height, state.screen)
state.Content.Invalidate()
}
state.Content.Event(event)
case <-state.invalidations:
state.Content.Draw(state.ctx)
- tb.Flush()
+ state.screen.Show()
default:
return false
}