diff --git a/main.go b/main.go index 2c77bf1..a43e314 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,9 @@ import ( tea "github.com/charmbracelet/bubbletea" ) +// Enum for the different launch types (browsers and CLI's) const ( - BrowserSessions int = iota // Enumerating the sections + BrowserSessions int = iota Commands ) @@ -26,8 +27,11 @@ type model struct { cursor []int choices Choices selected []SelectionSet + status string } +type statusMsg string + var browserSelection SelectionSet var commandSelection SelectionSet @@ -58,19 +62,26 @@ func initialModel() model { commandString: "btm --group --battery --color gruvbox-light", }}, }, - // An array maps which indicates which choices are selected. We're - // using the map like a mathematical set. The keys refer to the - // indexes of the `choices` slice, above. + // An array of maps which indicates which choices are selected. + // We're using the map like a mathematical set. The keys refer to + // the indexes of the `choices` slice, above. selected: []SelectionSet{browserSelection, commandSelection}, } } +func launch() tea.Msg { + return statusMsg("This is a test launch message.") +} + func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { + case statusMsg: + m.status = string(msg) + return m, tea.Quit case tea.KeyMsg: switch msg.String() { case "ctrl+c", "q": @@ -89,13 +100,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.cursor[m.activeSection] < len(m.choices[m.activeSection])-1 { m.cursor[m.activeSection]++ } - case "enter", " ": + case " ": _, ok := m.selected[m.activeSection][m.cursor[m.activeSection]] if ok { delete(m.selected[m.activeSection], m.cursor[m.activeSection]) } else { m.selected[m.activeSection][m.cursor[m.activeSection]] = struct{}{} } + case "enter": + return m, launch } } @@ -123,6 +136,7 @@ func (m model) View() string { } // s += fmt.Sprintf("\n%+v", m.selected) // debug + s += fmt.Sprintf("%s\n", m.status) s += "\nPress q to quit.\n" return s