add fuzzy finder to langlist cli

This commit is contained in:
2023-08-27 22:28:34 +05:30
parent 9ad072eba7
commit f586163648
8 changed files with 74 additions and 22 deletions

View File

@@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"github.com/ktr0731/go-fuzzyfinder"
"codeberg.org/aryak/mozhi/utils"
"github.com/spf13/cobra"
@@ -22,7 +22,21 @@ var translateCmd = &cobra.Command{
Long: `Translate.`,
Run: func(cmd *cobra.Command, args []string) {
if langlist == "sl" || langlist == "tl" {
fmt.Println(utils.LangList(engine, langlist))
list, err := utils.LangList(engine, langlist)
if err != nil {
fmt.Println(err)
}
idxs, err := fuzzyfinder.FindMulti(
list,
func(i int) string {
return list[i].Name
})
if err != nil {
fmt.Println(err)
}
for _, idx := range idxs {
fmt.Println("Selected Language:", list[idx].Id)
}
} else if engine == "all" {
fmt.Println(utils.TranslateAll(dest, source, query))
} else {