Correct or almost correct model
This commit is contained in:
parent
f0d76461dd
commit
4e810304f2
1 changed files with 41 additions and 27 deletions
68
main.go
68
main.go
|
@ -7,40 +7,54 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type commandChoice struct {
|
||||
const (
|
||||
BrowserSessions int = iota // Enumerating the sections
|
||||
Commands
|
||||
)
|
||||
|
||||
type sessionOrCommand struct {
|
||||
displayString string
|
||||
commandString string
|
||||
}
|
||||
|
||||
type Choices [][]sessionOrCommand
|
||||
|
||||
type model struct {
|
||||
browserSessionsCursor int
|
||||
commandsCursor int
|
||||
browserSessions []string
|
||||
commands []commandChoice
|
||||
selectedSessions map[int]struct{}
|
||||
selectedCommands map[int]struct{}
|
||||
activeSection int
|
||||
cursor []int
|
||||
choices Choices
|
||||
selected []map[int]struct{}
|
||||
}
|
||||
|
||||
func getBrowserSessions() []string {
|
||||
func getBrowserSessions() []sessionOrCommand {
|
||||
// Placeholder
|
||||
return []string{"primary", "breakfast"}
|
||||
return []sessionOrCommand{{
|
||||
displayString: "primary",
|
||||
commandString: "",
|
||||
}, {
|
||||
displayString: "breakfast",
|
||||
commandString: "",
|
||||
}}
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
return model{
|
||||
browserSessions: getBrowserSessions(),
|
||||
commands: []commandChoice{{
|
||||
displayString: "neomutt",
|
||||
commandString: "neomutt",
|
||||
}, {
|
||||
displayString: "bottom",
|
||||
commandString: "btm --group --battery --color gruvbox-light",
|
||||
}},
|
||||
// A map 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.
|
||||
selectedSessions: make(map[int]struct{}),
|
||||
selectedCommands: make(map[int]struct{}),
|
||||
activeSection: BrowserSessions,
|
||||
// Need syntax of two-dimensional slices
|
||||
choices: Choices{
|
||||
getBrowserSessions(),
|
||||
[]sessionOrCommand{{
|
||||
displayString: "neomutt",
|
||||
commandString: "neomutt",
|
||||
}, {
|
||||
displayString: "bottom",
|
||||
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.
|
||||
selected: make([]map[int]struct{}, 32, 32),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,17 +69,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
case "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
case "up", "k":
|
||||
if m.cursor > 0 {
|
||||
m.cursor--
|
||||
if m.cursor[m.activeSection] > 0 {
|
||||
m.cursor[m.activeSection]--
|
||||
}
|
||||
case "down", "j":
|
||||
if m.cursor < len(m.browserSessions)+len(m.commands)-1 {
|
||||
m.cursor++
|
||||
if m.cursor[m.activeSection] < len(m.browserSessions)+len(m.commands)-1 {
|
||||
m.cursor[m.activeSection]++
|
||||
}
|
||||
case "enter", " ":
|
||||
// TODO: Let's have two separate cursors, and have tab move the active
|
||||
// set from brower sessions to terminals.
|
||||
if m.cursor < len(m.browserSessions)-1 {
|
||||
if m.cursor[m.activeSection] < len(m.browserSessions)-1 {
|
||||
_, ok := m.selected[m.cursor]
|
||||
if ok {
|
||||
delete(m.selected, m.cursor)
|
||||
|
|
Loading…
Reference in a new issue