package ui import ( "git.bullercodeworks.com/brian/wandle" "git.bullercodeworks.com/brian/widdles" "github.com/nsf/termbox-go" ) type settingsScreen struct { ui *Ui initialized bool menu *widdles.TopMenu } type SettingsMsg ScreenMsg func NewSettingsScreen(u *Ui) *settingsScreen { return &settingsScreen{ ui: u, menu: widdles.NewTopMenu(0, 0, 0), } } func (s *settingsScreen) Init() wandle.Cmd { if s.initialized { return nil } s.initialized = true // Set up the top menu fileMenu := s.menu.NewSubMenu("File") quitOption := widdles.NewMenuItem("Quit") quitOption.Hotkey = termbox.KeyCtrlC quitOption.SetCommand(func() wandle.Msg { return wandle.Quit() }) fileMenu.AddOption(quitOption) gotoMenu := s.menu.NewSubMenu("Goto") timerListOption := widdles.NewMenuItem("Timer List") timerListOption.SetCommand(s.ui.GotoScreen(ListTimersId)) gotoMenu.AddOption(timerListOption) s.menu.Measure() return nil } func (s *settingsScreen) Update(msg wandle.Msg) wandle.Cmd { switch msg := msg.(type) { case ScreenMsg: case termbox.Event: return s.handleTermboxEvent(msg) } return nil } func (s *settingsScreen) View(style wandle.Style) { wandle.Print(1, 1, style, "Settings") if s.menu.IsActive() { s.menu.View(style) } } func (s *settingsScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd { if (msg.Type == termbox.EventKey && msg.Key == termbox.KeyEsc) || s.menu.IsActive() { return s.menu.Update(msg) } return nil } func (s *settingsScreen) gotoTimerList() wandle.Msg { return ScreenMsg{ source: SettingsId, command: CmdGotoTimerList, } }