45 lines
930 B
Go
45 lines
930 B
Go
|
package prompt
|
||
|
|
||
|
import (
|
||
|
"git.burning.moe/celediel/fml/internal/modlist"
|
||
|
|
||
|
"github.com/charmbracelet/huh"
|
||
|
"github.com/charmbracelet/log"
|
||
|
)
|
||
|
|
||
|
func makeOptions(mods *modlist.Modlist) []huh.Option[string] {
|
||
|
options := []huh.Option[string]{}
|
||
|
|
||
|
for _, mod := range mods.Mods {
|
||
|
option := huh.NewOption[string](mod.Name, mod.Name).Selected(mod.Enabled)
|
||
|
options = append(options, option)
|
||
|
}
|
||
|
|
||
|
return options
|
||
|
}
|
||
|
|
||
|
// Show shows the huh prompt to enable/disable mods from provided Modlist
|
||
|
// returns the names of enabled mods
|
||
|
func Show(mods *modlist.Modlist) ([]string, error) {
|
||
|
// TODO: use huh to enable/disable the mods somehow
|
||
|
var selected []string
|
||
|
|
||
|
form := huh.NewForm(
|
||
|
huh.NewGroup(
|
||
|
huh.NewMultiSelect[string]().
|
||
|
Options(makeOptions(mods)...).
|
||
|
Title("Factorio Mod List").
|
||
|
Value(&selected),
|
||
|
),
|
||
|
)
|
||
|
|
||
|
err := form.Run()
|
||
|
if err != nil {
|
||
|
return []string{}, err
|
||
|
}
|
||
|
|
||
|
log.Debug(selected)
|
||
|
|
||
|
return selected, nil
|
||
|
}
|