commit
61f0a3d74c
@ -0,0 +1,18 @@ |
||||
# Binaries for programs and plugins |
||||
*.exe |
||||
*.exe~ |
||||
*.dll |
||||
*.so |
||||
*.dylib |
||||
|
||||
# Test binary, built with |
||||
*.test |
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE |
||||
*.out |
||||
|
||||
# Dependency directories (remove the comment below to include it) |
||||
# vendor/ |
||||
|
||||
# Go workspace file |
||||
go.work |
@ -0,0 +1,18 @@ |
||||
module git.theadamcooper.com/breakfast |
||||
|
||||
go 1.18 |
||||
|
||||
require github.com/charmbracelet/bubbletea v0.20.0 |
||||
|
||||
require ( |
||||
github.com/containerd/console v1.0.3 // indirect |
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect |
||||
github.com/mattn/go-isatty v0.0.14 // indirect |
||||
github.com/mattn/go-runewidth v0.0.13 // indirect |
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect |
||||
github.com/muesli/reflow v0.3.0 // indirect |
||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect |
||||
github.com/rivo/uniseg v0.2.0 // indirect |
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect |
||||
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect |
||||
) |
@ -0,0 +1,26 @@ |
||||
github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc= |
||||
github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM= |
||||
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= |
||||
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= |
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= |
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= |
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= |
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= |
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= |
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= |
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= |
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= |
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= |
||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= |
||||
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= |
||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI= |
||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= |
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= |
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= |
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= |
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= |
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
||||
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0= |
||||
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= |
@ -0,0 +1,105 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
|
||||
tea "github.com/charmbracelet/bubbletea" |
||||
) |
||||
|
||||
type commandChoice struct { |
||||
displayString string |
||||
commandString string |
||||
} |
||||
|
||||
type model struct { |
||||
cursor int |
||||
browserSessions []string |
||||
commands []commandChoice |
||||
selectedSessions map[int]struct{} |
||||
selectedCommands map[int]struct{} |
||||
} |
||||
|
||||
func getBrowserSessions() []string { |
||||
// Placeholder
|
||||
return []string{"primary", "breakfast"} |
||||
} |
||||
|
||||
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{}), |
||||
} |
||||
} |
||||
|
||||
func (m model) Init() tea.Cmd { |
||||
return nil |
||||
} |
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
||||
switch msg := msg.(type) { |
||||
case tea.KeyMsg: |
||||
switch msg.String() { |
||||
case "ctrl+c", "q": |
||||
return m, tea.Quit |
||||
case "up", "k": |
||||
if m.cursor > 0 { |
||||
m.cursor-- |
||||
} |
||||
case "down", "j": |
||||
if m.cursor < len(m.choices)-1 { |
||||
m.cursor++ |
||||
} |
||||
case "enter", " ": |
||||
_, ok := m.selected[m.cursor] |
||||
if ok { |
||||
delete(m.selected, m.cursor) |
||||
} else { |
||||
m.selected[m.cursor] = struct{}{} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return m, nil |
||||
} |
||||
|
||||
func (m model) View() string { |
||||
s := "What should we buy at the market?\n\n" |
||||
|
||||
for i, choice := range m.choices { |
||||
cursor := " " |
||||
if m.cursor == i { |
||||
cursor = ">" |
||||
} |
||||
|
||||
checked := " " |
||||
if _, ok := m.selected[i]; ok { |
||||
checked = "x" |
||||
} |
||||
|
||||
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice) |
||||
} |
||||
|
||||
s += "\nPress q to quit.\n" |
||||
|
||||
return s |
||||
} |
||||
|
||||
func main() { |
||||
p := tea.NewProgram(initialModel()) |
||||
if err := p.Start(); err != nil { |
||||
fmt.Printf("Alas, there's been an error: %v", err) |
||||
os.Exit(1) |
||||
} |
||||
} |
Loading…
Reference in new issue