Skip to content

Commit 0c57e29

Browse files
committed
refactor: refactor confirmation logic and remove unused dependencies
- Remove `github.com/charmbracelet/huh` dependency from `go.mod`. - Remove `github.com/catppuccin/go` and `github.com/charmbracelet/x/exp/strings` dependencies from `go.mod`. - Remove `github.com/mitchellh/hashstructure/v2` dependency from `go.mod`. - Replace `github.com/erikgeiser/promptkit/confirmation` with a custom confirmation prompt in `commit.go`. - Update confirmation logic in `commit.go` to use `console.WaitForUserConfirm` with a default value. - Modify `diff_block_editor.go` to use `console.WaitForUserConfirm` with a default value for file creation and code application. - Refactor `confirm.go` to use `github.com/erikgeiser/promptkit/confirmation` for user confirmation prompts. - Remove redundant `WaitForUserConfirmApplyChanges` function from `confirm.go`. Signed-off-by: codiing-hui <wecoding@yeah.net>
1 parent 8f65485 commit 0c57e29

File tree

5 files changed

+12
-38
lines changed

5 files changed

+12
-38
lines changed

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/charmbracelet/bubbles v0.20.0
1212
github.com/charmbracelet/bubbletea v1.2.5-0.20241205214244-9306010a31ee
1313
github.com/charmbracelet/glamour v0.8.0
14-
github.com/charmbracelet/huh v0.6.0
1514
github.com/charmbracelet/lipgloss v1.0.0
1615
github.com/coding-hui/common v0.8.7
1716
github.com/coding-hui/go-prompt v0.2.8
@@ -48,10 +47,8 @@ require (
4847
github.com/atotto/clipboard v0.1.4 // indirect
4948
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
5049
github.com/aymerick/douceur v0.2.0 // indirect
51-
github.com/catppuccin/go v0.2.0 // indirect
5250
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
5351
github.com/charmbracelet/x/ansi v0.4.5 // indirect
54-
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
5552
github.com/charmbracelet/x/term v0.2.1 // indirect
5653
github.com/containerd/containerd v1.7.18 // indirect
5754
github.com/containerd/log v0.1.0 // indirect
@@ -89,7 +86,6 @@ require (
8986
github.com/mattn/go-tty v0.0.7 // indirect
9087
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
9188
github.com/mitchellh/copystructure v1.0.0 // indirect
92-
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
9389
github.com/mitchellh/reflectwalk v1.0.0 // indirect
9490
github.com/moby/docker-image-spec v1.3.1 // indirect
9591
github.com/moby/patternmatcher v0.6.0 // indirect

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ github.com/caarlos0/env/v9 v9.0.0 h1:SI6JNsOA+y5gj9njpgybykATIylrRMklbs5ch6wO6pc
4343
github.com/caarlos0/env/v9 v9.0.0/go.mod h1:ye5mlCVMYh6tZ+vCgrs/B95sj88cg5Tlnc0XIzgZ020=
4444
github.com/caarlos0/go-shellwords v1.0.12 h1:HWrUnu6lGbWfrDcFiHcZiwOLzHWjjrPVehULaTFgPp8=
4545
github.com/caarlos0/go-shellwords v1.0.12/go.mod h1:bYeeX1GrTLPl5cAMYEzdm272qdsQAZiaHgeF0KTk1Gw=
46-
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
47-
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
4846
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
4947
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
5048
github.com/certifi/gocertifi v0.0.0-20190105021004-abcd57078448/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
@@ -54,16 +52,12 @@ github.com/charmbracelet/bubbletea v1.2.5-0.20241205214244-9306010a31ee h1:xNijb
5452
github.com/charmbracelet/bubbletea v1.2.5-0.20241205214244-9306010a31ee/go.mod h1:Hbk5+oE4a7cDyjfdPi4sHZ42aGTMYcmHnVDhsRswn7A=
5553
github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs=
5654
github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw=
57-
github.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=
58-
github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=
5955
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
6056
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
6157
github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM=
6258
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
6359
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q=
6460
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
65-
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=
66-
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
6761
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
6862
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
6963
github.com/coding-hui/common v0.8.7 h1:f9iHZcdQLgRFW/nIJHVfBINuzzCKsUcwVIhfboxXe2s=
@@ -198,8 +192,6 @@ github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMK
198192
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
199193
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
200194
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
201-
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
202-
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
203195
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
204196
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
205197
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=

internal/cli/commit/commit.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
tea "github.com/charmbracelet/bubbletea"
11-
"github.com/erikgeiser/promptkit/confirmation"
1211
"github.com/fatih/color"
1312
"github.com/spf13/cobra"
1413

@@ -208,19 +207,13 @@ func (o *Options) AutoCommit(_ *cobra.Command, args []string) error {
208207
}
209208

210209
if o.preview && !o.noConfirm {
211-
input := confirmation.New("Commit preview summary?", confirmation.Yes)
212-
ready, err := input.RunPrompt()
213-
if err != nil {
214-
return errbook.Wrap("Could not run prompt.", err)
215-
}
216-
if !ready {
210+
if ok := console.WaitForUserConfirm(console.No, "Commit preview summary?"); !ok {
217211
return nil
218212
}
219213
}
220214

221215
if !o.noConfirm {
222-
change := console.WaitForUserConfirm("Do you want to change the commit message?")
223-
if change {
216+
if change := console.WaitForUserConfirm(console.No, "Do you want to change the commit message?"); change {
224217
m := ui.InitialTextareaPrompt(commitMessage)
225218
p := tea.NewProgram(m)
226219
if _, err := p.Run(); err != nil {

internal/ui/coders/diff_block_editor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (e *EditBlockCoder) applyEdit(_ context.Context, block PartialCodeBlock) er
125125
}
126126

127127
if !fileExists {
128-
if ok := console.WaitForUserConfirm("Whether to create the %s file? (Y/n)", block.Path); ok {
128+
if ok := console.WaitForUserConfirm(console.Yes, "Whether to create the %s file? (Y/n)", block.Path); !ok {
129129
if err := fileutil.WriteFile(absPath, []byte("")); err != nil {
130130
return err
131131
}
@@ -221,7 +221,7 @@ func (e *EditBlockCoder) Execute(ctx context.Context, messages []llms.ChatMessag
221221

222222
e.partialResponseContent = chatModel.Output
223223

224-
if ok := console.WaitForUserConfirm("Are you sure you want to apply these codes? (Y/n)"); ok {
224+
if ok := console.WaitForUserConfirm(console.Yes, "Are you sure you want to apply these codes? (Y/n)"); !ok {
225225
return errbook.NewUserErrorf("Apply edit cancelled!")
226226
}
227227

internal/ui/console/confirm.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@ package console
33
import (
44
"fmt"
55

6-
"github.com/charmbracelet/huh"
6+
"github.com/erikgeiser/promptkit/confirmation"
77
)
88

9-
func WaitForUserConfirm(format string, args ...interface{}) (confirm bool) {
10-
err := huh.Run(
11-
huh.NewConfirm().
12-
Title(fmt.Sprintf(format, args...)).
13-
Inline(true).
14-
Affirmative("Yes!").
15-
Negative("No.").
16-
Value(&confirm),
17-
)
9+
var No = confirmation.No
10+
var Yes = confirmation.Yes
11+
12+
func WaitForUserConfirm(defaultVal confirmation.Value, format string, args ...interface{}) bool {
13+
input := confirmation.New(fmt.Sprintf(format, args...), defaultVal)
14+
confirm, err := input.RunPrompt()
1815
if err != nil {
1916
return false
2017
}
21-
return
22-
}
23-
24-
func WaitForUserConfirmApplyChanges(format string, args ...interface{}) (confirm bool) {
25-
return true
18+
return confirm
2619
}

0 commit comments

Comments
 (0)