diff options
Diffstat (limited to 'lib/ui')
-rw-r--r-- | lib/ui/context.go | 2 | ||||
-rw-r--r-- | lib/ui/interfaces.go | 2 | ||||
-rw-r--r-- | lib/ui/ui.go | 45 |
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) - } } |