mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-06-27 12:21:25 +02:00
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:
committed by
Robin Jarry
parent
787cfbd9a9
commit
0fd5f41157
+1
-1
@@ -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}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ type Interactive interface {
|
||||
}
|
||||
|
||||
type Beeper interface {
|
||||
OnBeep(func() error)
|
||||
OnBeep(func())
|
||||
}
|
||||
|
||||
type DrawableInteractive interface {
|
||||
|
||||
+19
-28
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user