-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
52 lines (41 loc) · 1.18 KB
/
config.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
44
45
46
47
48
49
50
51
52
package options
import (
"errors"
"github.com/MohammadBnei/go-ai-cli/service"
"github.com/MohammadBnei/go-ai-cli/ui/config"
"github.com/MohammadBnei/go-ai-cli/ui/event"
"github.com/MohammadBnei/go-ai-cli/ui/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/viper"
)
type configModel struct {
list list.Model
title string
}
const (
SAVE_CONFIG = "save"
SETTINGS = "settings"
)
func NewConfigOptionsModel(pc *service.PromptConfig) tea.Model {
items := getConfOItemsAsUiList(pc)
return list.NewFancyListModel("Options > Config", items, &list.DelegateFunctions{
ChooseFn: func(id string) tea.Cmd {
switch id {
case SAVE_CONFIG:
return tea.Sequence(event.RemoveStack(nil), event.Error(viper.WriteConfig()))
case SETTINGS:
return event.AddStack(config.NewConfigModel(pc), "Loading Config...")
case CLEAR:
pc.ChatMessages.ClearMessages()
return event.RemoveStack(list.Model{})
}
return event.Error(errors.New("unknown option: " + id))
},
})
}
func getConfOItemsAsUiList(pc *service.PromptConfig) []list.Item {
return []list.Item{
{ItemId: SETTINGS, ItemTitle: "Settings"},
{ItemId: SAVE_CONFIG, ItemTitle: "Save Config"},
}
}