Implementing the library

This commit is contained in:
aditya-K2 2021-11-28 23:33:34 +05:30
parent acc494682a
commit baa063a712

24
main.go
View File

@ -1,13 +1,12 @@
package main package main
import ( import (
"sort"
"strconv" "strconv"
"time" "time"
"github.com/aditya-K2/fuzzy"
"github.com/aditya-K2/goMP/cache" "github.com/aditya-K2/goMP/cache"
"github.com/aditya-K2/goMP/config" "github.com/aditya-K2/goMP/config"
"github.com/aditya-K2/goMP/search"
"github.com/fhs/gompd/mpd" "github.com/fhs/gompd/mpd"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -58,6 +57,7 @@ func main() {
Repeat, _ = strconv.ParseBool(_v["repeat"]) Repeat, _ = strconv.ParseBool(_v["repeat"])
ARTIST_TREE, err = GenerateArtistTree() ARTIST_TREE, err = GenerateArtistTree()
ARTIST_TREE_CONTENT := ConvertToArray()
NOTIFICATION_SERVER = NewNotificationServer() NOTIFICATION_SERVER = NewNotificationServer()
NOTIFICATION_SERVER.Start() NOTIFICATION_SERVER.Start()
@ -201,26 +201,14 @@ func main() {
UI.SearchBar.SetAutocompleteFunc(func(c string) []string { UI.SearchBar.SetAutocompleteFunc(func(c string) []string {
if c != "" && c != " " && c != " " { if c != "" && c != " " && c != " " {
var p search.PairList _, _, w, _ := UI.SearchBar.GetRect()
for k2, v := range ARTIST_TREE { matches := fuzzy.Find(c, ARTIST_TREE_CONTENT)
p = append(p, search.Pair{Key: k2, Value: search.GetLevenshteinDistance(c, k2)})
for k1, v1 := range v {
p = append(p, search.Pair{Key: k1, Value: search.GetLevenshteinDistance(c, k1)})
for k := range v1 {
p = append(p, search.Pair{Key: k, Value: search.GetLevenshteinDistance(c, k)})
}
}
}
sort.Sort(p)
var suggestions []string var suggestions []string
i := 0 for i, match := range matches {
for _, k := range p {
if i == 10 { if i == 10 {
break break
} }
_, _, w, _ := UI.SearchBar.GetRect() suggestions = append(suggestions, getFormattedString(match.Str, w-2))
suggestions = append(suggestions, getFormattedString(k.Key, w-2))
i++
} }
return suggestions return suggestions
} else { } else {