aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2024-02-12 06:26:17 -0600
committerRobin Jarry <robin@jarry.cc>2024-02-12 13:48:46 +0100
commit0fd5f4115792e706f73202d77fac404c0033333b (patch)
treeb160998cab40d62efb38552da4028a744c80e723 /lib
parent787cfbd9a90a26072a8dd61a28eca11dd6e20c04 (diff)
downloadaerc-0fd5f4115792e706f73202d77fac404c0033333b.tar.gz
aerc-0fd5f4115792e706f73202d77fac404c0033333b.zip
ui: initialize vaxis directly, drop tcell.Screen initialization
Use Vaxis library directly to initialize the UI, dropping the need for a tcell Screen implementation Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/context.go2
-rw-r--r--lib/ui/interfaces.go2
-rw-r--r--lib/ui/ui.go45
3 files changed, 20 insertions, 29 deletions
diff --git a/lib/ui/context.go b/lib/ui/context.go
index 10089179..f1cc2a95 100644
--- a/lib/ui/context.go
+++ b/lib/ui/context.go
@@ -30,7 +30,7 @@ func (ctx *Context) Window() vaxis.Window {
return ctx.window
}
-func NewContext(width, height int, vx *vaxis.Vaxis, p func(*Popover)) *Context {
+func NewContext(vx *vaxis.Vaxis, p func(*Popover)) *Context {
win := vx.Window()
return &Context{win, 0, 0, p}
}
diff --git a/lib/ui/interfaces.go b/lib/ui/interfaces.go
index 8ed727cc..3f2f9509 100644
--- a/lib/ui/interfaces.go
+++ b/lib/ui/interfaces.go
@@ -30,7 +30,7 @@ type Interactive interface {
}
type Beeper interface {
- OnBeep(func() error)
+ OnBeep(func())
}
type DrawableInteractive interface {
diff --git a/lib/ui/ui.go b/lib/ui/ui.go
index 02e945c0..f17ca4b3 100644
--- a/lib/ui/ui.go
+++ b/lib/ui/ui.go
@@ -49,39 +49,32 @@ var state struct {
}
func Initialize(content DrawableInteractive) error {
- screen, err := tcell.NewScreen()
- if err != nil {
- return err
- }
-
opts := vaxis.Options{
- DisableMouse: !config.Ui.MouseEnabled,
+ DisableMouse: !config.Ui.MouseEnabled,
+ DisableKittyKeyboard: true,
}
- if err = screen.Init(opts); err != nil {
+ vx, err := vaxis.New(opts)
+ if err != nil {
return err
}
- vx := screen.Vaxis()
-
vx.Window().Clear()
vx.HideCursor()
- width, height := vx.Window().Size()
-
state.content = content
state.vx = vx
- state.ctx = NewContext(width, height, state.vx, onPopover)
+ state.ctx = NewContext(state.vx, onPopover)
Invalidate()
if beeper, ok := content.(DrawableInteractiveBeeper); ok {
- beeper.OnBeep(screen.Beep)
+ beeper.OnBeep(vx.Bell)
}
content.Focus(true)
go func() {
defer log.PanicHandler()
for event := range vx.Events() {
- Events <- tcell.TcellEvent(event)
+ Events <- event
}
}()
@@ -143,20 +136,18 @@ func Render() {
}
func HandleEvent(event vaxis.Event) {
- if event, ok := event.(*tcell.EventResize); ok {
- state.vx.Window().Clear()
- width, height := event.Size()
- state.ctx = NewContext(width, height, state.vx, onPopover)
+ switch event := event.(type) {
+ case vaxis.Resize:
+ state.ctx = NewContext(state.vx, onPopover)
Invalidate()
- }
- if event, ok := event.(tcell.VaxisEvent); ok {
- if _, ok := event.Vaxis().(vaxis.Redraw); ok {
- Invalidate()
+ case vaxis.Redraw:
+ Invalidate()
+ default:
+ event = tcell.TcellEvent(event)
+ // if we have a popover, and it can handle the event, it does so
+ if state.popover == nil || !state.popover.Event(event) {
+ // otherwise, we send the event to the main content
+ state.content.Event(event)
}
}
- // if we have a popover, and it can handle the event, it does so
- if state.popover == nil || !state.popover.Event(event) {
- // otherwise, we send the event to the main content
- state.content.Event(event)
- }
}