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>
This commit is contained in:
Tim Culverhouse
2024-02-12 06:26:17 -06:00
committed by Robin Jarry
parent 787cfbd9a9
commit 0fd5f41157
3 changed files with 21 additions and 30 deletions
+1 -1
View File
@@ -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}
}
+1 -1
View File
@@ -30,7 +30,7 @@ type Interactive interface {
}
type Beeper interface {
OnBeep(func() error)
OnBeep(func())
}
type DrawableInteractive interface {
+19 -28
View File
@@ -49,39 +49,32 @@ var state struct {
}
func Initialize(content DrawableInteractive) error {
screen, err := tcell.NewScreen()
opts := vaxis.Options{
DisableMouse: !config.Ui.MouseEnabled,
DisableKittyKeyboard: true,
}
vx, err := vaxis.New(opts)
if err != nil {
return err
}
opts := vaxis.Options{
DisableMouse: !config.Ui.MouseEnabled,
}
if err = screen.Init(opts); 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)
}
}