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