-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
main.go
43 lines (38 loc) · 752 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"log"
fuzzyfinder "github.com/ktr0731/go-fuzzyfinder"
)
type Track struct {
Name string
AlbumName string
Artist string
}
var tracks = []Track{
{"foo", "album1", "artist1"},
{"bar", "album1", "artist1"},
{"foo", "album2", "artist1"},
{"baz", "album2", "artist2"},
{"baz", "album3", "artist2"},
}
func main() {
idx, err := fuzzyfinder.FindMulti(
tracks,
func(i int) string {
return tracks[i].Name
},
fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
if i == -1 {
return ""
}
return fmt.Sprintf("Track: %s (%s)\nAlbum: %s",
tracks[i].Name,
tracks[i].Artist,
tracks[i].AlbumName)
}))
if err != nil {
log.Fatal(err)
}
fmt.Printf("selected: %v\n", idx)
}