charmbracelet / huh

Build terminal forms and prompts 🤷🏻‍♀️
MIT License
4.39k stars 126 forks source link

feat: Adjust `Confirm Buttons` within the Confirm Field #425

Closed prithvijj closed 1 month ago

prithvijj commented 1 month ago

Changes

Testing

Made some changes within examples/git/main.go to test out these changes

diff --git a/examples/git/main.go b/examples/git/main.go
index 06a94f9..3d1cab7 100644
--- a/examples/git/main.go
+++ b/examples/git/main.go
@@ -2,6 +2,7 @@ package main

 import (
    "github.com/charmbracelet/huh"
+   "github.com/charmbracelet/lipgloss"
 )

 // types is the possible commit types specified by the conventional commit spec.
@@ -12,19 +13,22 @@ var types = []string{"fix", "feat", "docs", "style", "refactor", "test", "chore"
 // And then prompts for the summary and detailed description of the message and
 // uses the values provided as the summary and details of the message.
 func main() {
-   var commit, scope string
-   var summary, description string
+   // var commit, scope string
+   // var summary, description string
    var confirm bool

    huh.NewForm(
-       huh.NewGroup(
-           huh.NewInput().Title("Type").Value(&commit).Placeholder("feat").Suggestions(types),
-           huh.NewInput().Title("Scope").Value(&scope).Placeholder("scope"),
-       ),
-       huh.NewGroup(
-           huh.NewInput().Title("Summary").Value(&summary).Placeholder("Summary of changes"),
-           huh.NewText().Title("Description").Value(&description).Placeholder("Detailed description of changes"),
-       ),
-       huh.NewGroup(huh.NewConfirm().Title("Commit changes?").Value(&confirm)),
+       // huh.NewGroup(
+       //  huh.NewInput().Title("Type").Value(&commit).Placeholder("feat").Suggestions(types),
+       //  huh.NewInput().Title("Scope").Value(&scope).Placeholder("scope"),
+       // ),
+       // huh.NewGroup(
+       //  huh.NewInput().Title("Summary").Value(&summary).Placeholder("Summary of changes"),
+       //  huh.NewText().Title("Description").Value(&description).Placeholder("Detailed description of changes"),
+       // ),
+       huh.NewGroup(huh.NewConfirm().Title("Commit changes?Commit changes?Commit changes?Commit changes?Commit changes?Commit changes?Commit changes?").Value(&confirm)),
+       huh.NewGroup(huh.NewConfirm().Title("Commit changes?Commit changes?").Value(&confirm)),
+       huh.NewGroup(huh.NewConfirm().WithButtonAlignment(lipgloss.Left).Title("Commit changes?Commit changes?Commit changes?Commit changes?Commit changes?Commit changes?Commit changes?").Value(&confirm)),
+       huh.NewGroup(huh.NewConfirm().WithButtonAlignment(lipgloss.Left).Title("Commit changes?Commit changes?").Value(&confirm)),
    ).Run()
 }

image

Before: Confirm buttons would appear in the center of the confirm view field

(Long Title, with buttons aligned in the center) image

(Short title, with buttons aligned in the center) image

After: adding withButtonAlignment(lipgloss.Left), confirm buttons appears on the left of the confirm view field

(Long Title, with buttons aligned in the left) image

(Short title, with buttons aligned in the left) image

Other Notes

bashbunni commented 1 month ago

Hey @prithvijj thank you so much for your work on this! I couldn't make changes to this PR for some reason, so had to create a new one to update the godoc for the function you introduced. It's now merged to main and we're planning on adding additional tests for this in a follow up PR :) Thanks again!! If you're on the Discord, please let us know your username so we can add you as a contributor over there too 🎊

bashbunni commented 1 month ago

Closing as these changes were added in #427 instead

prithvijj commented 1 month ago

Hey @prithvijj thank you so much for your work on this! I couldn't make changes to this PR for some reason, so had to create a new one to update the godoc for the function you introduced. It's now merged to main and we're planning on adding additional tests for this in a follow up PR :) Thanks again!! If you're on the Discord, please let us know your username so we can add you as a contributor over there too 🎊

Thanks for reviewing and merging it @bashbunni ! Weird that changes couldn't be made to the PR, guess I can check my github stuff's configured correctly

Yepp, already saw that I got the contributor tag there too! Appreciate it a lot !