boltbrowser/ui/screen_browse.go
2022-04-14 11:32:39 -05:00

76 lines
1.3 KiB
Go

package ui
import (
"time"
"git.bullercodeworks.com/brian/wandle"
"git.bullercodeworks.com/brian/widdles"
"github.com/nsf/termbox-go"
)
const (
//BS_CmdGotoAbout = BrowseId | iota
)
type BrowseMsg struct {
source int
data interface{}
err error
}
type browseScreen struct {
ui *Ui
dbPath string
menu *widdles.TopMenu
status *widdles.Text
statusTimeout time.Duration
statusTime time.Time
}
func NewBrowseScreen(u *Ui) *browseScreen {
w, h := termbox.Size()
return &browseScreen{
ui: u,
menu: widdles.NewTopMenu(0, 0, w),
status: widdles.NewText("", 0, h),
}
}
func (s *browseScreen) Init() wandle.Cmd {
return nil
}
func (s *browseScreen) Update(msg wandle.Msg) wandle.Cmd {
switch msg := msg.(type) {
case BrowseMsg:
return s.handleBrowseMsg(msg)
case termbox.Event:
return s.handleTermboxEvent(msg)
}
return nil
}
func (s *browseScreen) handleBrowseMsg(msg BrowseMsg) wandle.Cmd {
switch msg.source {
}
return nil
}
func (s *browseScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd {
if (msg.Type == termbox.EventKey && msg.Key == termbox.KeyEsc) || s.menu.IsActive() {
return s.menu.Update(msg)
}
switch msg.Type {
case termbox.EventKey:
if msg.Ch == '?' {
return wandle.SwitchScreenCmd(NewAboutScreen(s.ui))
}
}
return nil
}
func (s *browseScreen) View(style wandle.Style) {
}