package menu import ( "sync" "github.com/gdamore/tcell" ) type Menu struct { model *menuModel once sync.Once MenuView } func (m *Menu) SetLines(lines []string) { m.Init() mm := m.model mm.width = 0 mm.height = len(lines) mm.lines = lines for _, l := range lines { if len(l) > mm.width { mm.width = len(l) } } m.MenuView.SetModel(mm) } func (m *Menu) SetStyle(style tcell.Style) { m.model.style = style m.MenuView.SetStyle(style) } func (m *Menu) SetSelectedStyle(style tcell.Style) { m.MenuView.SetSelectedStyle(style) } func (m *Menu) EnableCursor(on bool) { m.Init() m.model.cursor = on } func (m *Menu) HideCursor(on bool) { m.Init() m.model.hide = on } func (m *Menu) Init() { m.once.Do(func() { mm := &menuModel{ lines: []string{}, width: 0, cursor: true, hide: false, } m.model = mm m.MenuView.Init() m.MenuView.SetModel(mm) }) } func NewMenu() *Menu { m := &Menu{} m.Init() return m }