fml/internal/prompt/prompt.go
Lilian Jónsdóttir ba36cba7bf initial code commit - basic functionality works
- automatically adds mods found in mods folder that aren't in mod-list.json
- read/write modlist from mod-list.json
- enable/disable mods
2024-02-09 10:53:06 -08:00

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
}