refactor: remove picker package
This commit is contained in:
parent
212b28aef4
commit
f7fc1ea0fa
2 changed files with 0 additions and 80 deletions
|
|
@ -1,23 +0,0 @@
|
|||
package picker
|
||||
|
||||
type Item struct {
|
||||
text string
|
||||
selected func()
|
||||
}
|
||||
|
||||
func NewItem(text string, selected func()) *Item {
|
||||
return &Item{
|
||||
text: text,
|
||||
selected: selected,
|
||||
}
|
||||
}
|
||||
|
||||
type Items []*Item
|
||||
|
||||
func (is Items) String(i int) string {
|
||||
return is[i].text
|
||||
}
|
||||
|
||||
func (is Items) Len() int {
|
||||
return len(is)
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package picker
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"github.com/sahilm/fuzzy"
|
||||
)
|
||||
|
||||
type Picker struct {
|
||||
*tview.Flex
|
||||
Input *tview.InputField
|
||||
List *tview.List
|
||||
|
||||
app *tview.Application
|
||||
items Items
|
||||
}
|
||||
|
||||
func New(app *tview.Application, items Items) *Picker {
|
||||
p := &Picker{
|
||||
Flex: tview.NewFlex(),
|
||||
Input: tview.NewInputField(),
|
||||
List: tview.NewList(),
|
||||
|
||||
app: app,
|
||||
items: items,
|
||||
}
|
||||
|
||||
// Render all of the items initially.
|
||||
p.changed("")
|
||||
|
||||
p.Input.SetChangedFunc(p.changed)
|
||||
p.List.ShowSecondaryText(false).SetFocusFunc(func() {
|
||||
app.SetFocus(p.Input)
|
||||
})
|
||||
p.Flex.
|
||||
SetDirection(tview.FlexRow).
|
||||
AddItem(p.Input, 3, 1, true).
|
||||
AddItem(p.List, 0, 1, false)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Picker) changed(text string) {
|
||||
var fuzzied Items
|
||||
if text == "" {
|
||||
fuzzied = append(fuzzied, p.items...)
|
||||
} else {
|
||||
matches := fuzzy.FindFrom(text, p.items)
|
||||
for _, match := range matches {
|
||||
fuzzied = append(fuzzied, p.items[match.Index])
|
||||
}
|
||||
}
|
||||
|
||||
p.List.Clear()
|
||||
|
||||
for _, item := range fuzzied {
|
||||
p.List.AddItem(item.text, "", 0, item.selected)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue