mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
add barebones listdelegate
This commit is contained in:
46
ui/listdelegate.go
Normal file
46
ui/listdelegate.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type selectableDelegate struct{}
|
||||
|
||||
func (s selectableDelegate) Height() int { return 1 }
|
||||
|
||||
func (s selectableDelegate) Spacing() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (s selectableDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s selectableDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
|
||||
x, ok := item.(selectable)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if x.selected {
|
||||
w.Write([]byte(" [X] " + x.text))
|
||||
} else {
|
||||
w.Write([]byte(" [ ] " + x.text))
|
||||
}
|
||||
}
|
||||
|
||||
type delegateKeyMap struct {
|
||||
toggle key.Binding
|
||||
}
|
||||
|
||||
func newDelegateKeyMap() *delegateKeyMap {
|
||||
return &delegateKeyMap{
|
||||
toggle: key.NewBinding(
|
||||
key.WithKeys("space"),
|
||||
key.WithHelp("space", "choose"),
|
||||
),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user