aboutsummaryrefslogtreecommitdiff
path: root/selecting.go
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-04-08 00:10:13 +0100
committerAria Shrimpton <me@aria.rip>2024-04-08 00:10:13 +0100
commit8c49b12e5b9563113393f9d3a28499fb8538ddcb (patch)
tree8f8d8d3ebc724256355b5d1974e41f7960005eec /selecting.go
parentf15d79198259ae3107fd5847ba8127ddf863af80 (diff)
actually filter based on initial command line
Diffstat (limited to 'selecting.go')
-rw-r--r--selecting.go42
1 files changed, 34 insertions, 8 deletions
diff --git a/selecting.go b/selecting.go
index 0817d3d..a56ccee 100644
--- a/selecting.go
+++ b/selecting.go
@@ -8,30 +8,56 @@ import (
)
type selectingModel struct {
+ initialFilter string
list list.Model
}
-func StartSelecting() selectingModel {
+func StartSelecting(initialFilter string) *selectingModel {
items, err := getItems()
if err != nil {
panic(err)
}
- list := list.New(items, list.NewDefaultDelegate(), 0, 0)
- list.Title = "Commands"
+ lst := list.New(items, list.NewDefaultDelegate(), 0, 0)
+ lst.Title = "Commands"
m := selectingModel{
- list: list,
+ list: lst,
+ initialFilter: initialFilter,
}
- return m
+ return &m
}
-func (m selectingModel) Init() tea.Cmd {
+func (m *selectingModel) Init() tea.Cmd {
+ if m.initialFilter != "" {
+ // ok so this is scuffed!
+ // there's no way to just set the filter, so instead we mimic typing it.
+ // we can ignore every command except the last one, which will just update our visible items
+ lst, cmd := m.list.Update(tea.KeyMsg{
+ Type: tea.KeyRunes,
+ Runes: []rune{'/'},
+ });
+
+ for _, chr := range m.initialFilter {
+ lst, cmd = lst.Update(tea.KeyMsg{
+ Type: tea.KeyRunes,
+ Runes: []rune{chr},
+ });
+ }
+
+ lst, _ = lst.Update(tea.KeyMsg{
+ Type: tea.KeyEnter,
+ Runes: []rune{},
+ })
+ m.list = lst;
+ return tea.Batch(tea.EnterAltScreen, cmd);
+ }
+
return tea.EnterAltScreen
}
-func (m selectingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+func (m *selectingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {
@@ -97,7 +123,7 @@ func (m selectingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
-func (m selectingModel) View() string {
+func (m *selectingModel) View() string {
return appStyle.Render(m.list.View())
}