diff --git a/internal/iostreams/forms.go b/internal/iostreams/forms.go index 532a521b..66b35d5f 100644 --- a/internal/iostreams/forms.go +++ b/internal/iostreams/forms.go @@ -82,15 +82,19 @@ func inputForm(io *IOStreams, _ context.Context, message string, cfg InputPrompt // buildConfirmForm constructs an interactive form for yes/no confirmation prompts. func buildConfirmForm(io *IOStreams, message string, choice *bool) *huh.Form { - field := huh.NewConfirm(). + field := huh.NewSelect[bool](). Title(message). + Options( + huh.NewOption("Yes", true), + huh.NewOption("No", false), + ). Value(choice) return newForm(io, field) } // confirmForm interactively prompts for a yes/no confirmation. -func confirmForm(io *IOStreams, _ context.Context, message string, defaultValue bool) (bool, error) { - var choice = defaultValue +func confirmForm(io *IOStreams, _ context.Context, message string, _ bool) (bool, error) { + var choice = true err := buildConfirmForm(io, message, &choice).Run() if errors.Is(err, huh.ErrUserAborted) { return false, slackerror.New(slackerror.ErrProcessInterrupted) diff --git a/internal/iostreams/forms_test.go b/internal/iostreams/forms_test.go index 721d4e6c..eb3ea821 100644 --- a/internal/iostreams/forms_test.go +++ b/internal/iostreams/forms_test.go @@ -113,17 +113,17 @@ func TestConfirmForm(t *testing.T) { assert.True(t, choice) }) - t.Run("toggle changes value", func(t *testing.T) { + t.Run("arrow keys change selection", func(t *testing.T) { choice := false f := buildConfirmForm(nil, "Continue?", &choice) f.Update(f.Init()) - // Toggle to Yes - f.Update(tea.KeyPressMsg{Code: tea.KeyLeft}) + // Move down to Yes + f.Update(tea.KeyPressMsg{Code: tea.KeyDown}) assert.True(t, choice) - // Toggle back to No - f.Update(tea.KeyPressMsg{Code: tea.KeyRight}) + // Move back up to No + f.Update(tea.KeyPressMsg{Code: tea.KeyUp}) assert.False(t, choice) }) } @@ -450,12 +450,12 @@ func TestFormsAccessible(t *testing.T) { assert.Contains(t, out.String(), "Pick one (press Enter for 1)") }) - t.Run("confirm form accepts yes/no input", func(t *testing.T) { + t.Run("confirm form accepts numbered input", func(t *testing.T) { var choice bool f := buildConfirmForm(io, "Continue?", &choice) var out strings.Builder - err := f.WithOutput(&out).WithInput(strings.NewReader("y\n")).Run() + err := f.WithOutput(&out).WithInput(strings.NewReader("1\n")).Run() assert.NoError(t, err) assert.True(t, choice)