diff options
| author | ewy <ewy0@protonmail.com> | 2026-05-02 16:23:36 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-05-02 16:23:36 +0200 |
| commit | c01a06e38d0b0331f459cd439ce7706ef1556e50 (patch) | |
| tree | 8bee63be92b6301d169be6113dfc3bbf16d37c9e /menu/model.go | |
| parent | 1e932e7015ac9d21a1f92ad57cd0c109f58bb29f (diff) | |
* fix infinite loop on not found
* add bash tab completion script (will have install option in the future)
* add search to tui (bound to / and ?)
Diffstat (limited to 'menu/model.go')
| -rw-r--r-- | menu/model.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/menu/model.go b/menu/model.go index aa7b00e..4480c96 100644 --- a/menu/model.go +++ b/menu/model.go @@ -1,6 +1,7 @@ package menu import ( + "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/x/term" "github.com/ewy1/pik/model" @@ -9,6 +10,7 @@ import ( "github.com/ewy1/pik/viewport" "github.com/spf13/pflag" "os" + "strings" ) type Model struct { @@ -21,9 +23,31 @@ type Model struct { Height int Alt bool AutoAlt bool + Search textinput.Model Motd string } +func (m *Model) Highlights(src *model.HydratedSource, t model.HydratedTarget) bool { + val := m.Search.Value() + if val == "" { + return false + } + + if strings.Contains(t.Target().Label(), val) { + return true + } + + if strings.Contains(t.Description(src), val) { + return true + } + + if strings.Contains(strings.Join(append(t.Target().Sub(), t.Target().Label()), " "), val) { + return true + } + + return false +} + func (m *Model) Init() tea.Cmd { _, h, err := term.GetSize(0) if err != nil { @@ -79,6 +103,9 @@ func (m *Model) View() string { } result := m.State() result = viewport.Process(result, m.Height) + if m.Search.Focused() { + result = m.AddSearch(result) + } return result } @@ -89,13 +116,16 @@ func (m *Model) Result() (*model.HydratedSource, model.HydratedTarget) { return m.SourceIndices[m.Index], m.Indices[m.Index] } -func (m *Model) Validate() { +func (m *Model) Validate() (clamped bool) { if m.Index < 0 { m.Index = 0 + return true } if m.Index > len(m.Indices)-1 { m.Index = len(m.Indices) - 1 + return true } + return false } var ForcedInlineTerminals = map[string]string{ @@ -117,6 +147,7 @@ func NewModel(st *model.State, hydrators []model.Modder) *Model { SourceIndices: make(map[int]*model.HydratedSource), AutoAlt: !pflag.Lookup("inline").Changed && !isBanned, Motd: motd.One(), + Search: textinput.New(), } idx := 0 for _, src := range st.Sources { |
