[#1] Prints test launch string

This commit is contained in:
Adam Cooper 2022-05-12 03:11:26 -04:00
parent bc1b6f60a4
commit a03f288682
1 changed files with 19 additions and 5 deletions

24
main.go
View File

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