-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.go
More file actions
193 lines (161 loc) · 3.89 KB
/
Copy pathhelper.go
File metadata and controls
193 lines (161 loc) · 3.89 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package main
import (
"fmt"
"os"
"charm.land/bubbles/v2/list"
tea "charm.land/bubbletea/v2"
"github.com/yashranjan1/commit/internal/components"
"github.com/yashranjan1/commit/internal/messages"
"github.com/yashranjan1/commit/internal/requests"
)
func InitFeedbackArea() *components.InputForm {
title := "What would you like to change about the commit? (press shift+enter to make a new line)"
onAccept := func(msg string) tea.Cmd {
return func() tea.Msg {
return messages.Correction{
Prompt: msg,
}
}
}
return components.NewInputForm(title, onAccept, 3)
}
func InitAPIKey() *components.InputForm {
title := "Enter your API key"
onAccept := func(msg string) tea.Cmd {
return func() tea.Msg {
return messages.APIEntered{
APIKey: msg,
}
}
}
return components.NewInputForm(title, onAccept, 3)
}
func InitChangeArea() *components.InputForm {
title := "Make your change"
onAccept := func(msg string) tea.Cmd {
return func() tea.Msg {
return messages.ChangedCommit{
Commit: msg,
}
}
}
return components.NewInputForm(title, onAccept, 7)
}
func InitOllamaOpts() *components.SelectForm {
items := []list.Item{
components.Option{
Name: "Start it",
Value: 0,
},
components.Option{
Name: "No I wanna write my own commit (exit)",
Value: 1,
},
}
onSelect := func(item components.Option) tea.Cmd {
return func() tea.Msg {
return messages.StartOllama{
Msg: item.Value,
}
}
}
config := components.SelectFormConfig{
Title: "Ollama server not running, would you like me to start it?",
Items: items,
Width: 100,
OnSelect: onSelect,
}
l := components.InitSelectForm(config)
return l
}
func InitCommitConfirmOpts() *components.SelectForm {
items := []list.Item{
components.Option{
Name: "Yes, commit it",
Value: 0,
},
components.Option{
Name: "No, I want to request a change",
Value: 1,
},
components.Option{
Name: "No, I want to make some changes",
Value: 2,
},
}
onSelect := func(item components.Option) tea.Cmd {
return func() tea.Msg {
return messages.CommitConfirmation{
Msg: item.Value,
}
}
}
config := components.SelectFormConfig{
Title: "Would you like to commit this? If yes, the following command will be run: git commit -m <COMMIT_MESSAGE>",
Items: items,
Width: 100,
OnSelect: onSelect,
}
l := components.InitSelectForm(config)
return l
}
func InitPickProvider() *components.SelectForm {
items := []list.Item{}
providers := []string{
"Ollama",
"Gemini",
}
for i, provider := range providers {
items = append(items,
components.Option{
Name: provider,
Value: i,
},
)
}
onSelect := func(item components.Option) tea.Cmd {
return func() tea.Msg {
return messages.ProviderPicked{
Name: item.Name,
}
}
}
path, _ := os.UserConfigDir()
title := fmt.Sprintf("You haven't picked a provider to use, which one would you like to use? (you can change your selection in the \"%s/commit/config.json\" file)", path)
config := components.SelectFormConfig{
Title: title,
Items: items,
Width: 100,
OnSelect: onSelect,
}
l := components.InitSelectForm(config)
return l
}
func InitModelPickOpts(models requests.GetModelsResponse) *components.SelectForm {
items := []list.Item{}
for i, model := range models.Models {
items = append(items,
components.Option{
Name: model.Name,
Value: i,
},
)
}
onSelect := func(item components.Option) tea.Cmd {
return func() tea.Msg {
return messages.ModelPicked{
Name: item.Name,
}
}
}
path, _ := os.UserConfigDir()
title := fmt.Sprintf("You haven't picked a model to use, which one would you like to use? (you can change your selection in the \"%s/commit/config.json\" file)", path)
config := components.SelectFormConfig{
Title: title,
Items: items,
Width: 100,
OnSelect: onSelect,
}
l := components.InitSelectForm(config)
return l
}