forked from charmbracelet/huh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into trim-empty-help
- Loading branch information
Showing
31 changed files
with
1,065 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/charmbracelet/huh" | ||
) | ||
|
||
type consumable int | ||
|
||
const ( | ||
fruits consumable = iota | ||
vegetables | ||
drinks | ||
) | ||
|
||
func (c consumable) String() string { | ||
return [...]string{"fruit", "vegetable", "drink"}[c] | ||
} | ||
|
||
func main() { | ||
|
||
var category consumable | ||
type opts []huh.Option[string] | ||
|
||
var choice string | ||
|
||
// Then ask for a specific food item based on the previous answer. | ||
err := | ||
huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewSelect[consumable](). | ||
Title("What are you in the mood for?"). | ||
Value(&category). | ||
Options( | ||
huh.NewOption("Some fruit", fruits), | ||
huh.NewOption("A vegetable", vegetables), | ||
huh.NewOption("A drink", drinks), | ||
), | ||
), | ||
|
||
huh.NewGroup( | ||
huh.NewSelect[string](). | ||
Title("Okay, what kind of fruit are you in the mood for?"). | ||
Options( | ||
huh.NewOption("Tangerine", "tangerine"), | ||
huh.NewOption("Canteloupe", "canteloupe"), | ||
huh.NewOption("Pomelo", "pomelo"), | ||
huh.NewOption("Grapefruit", "grapefruit"), | ||
). | ||
Value(&choice), | ||
).WithHideFunc(func() bool { return category != fruits }), | ||
|
||
huh.NewGroup( | ||
huh.NewSelect[string](). | ||
Title("Okay, what kind of vegetable are you in the mood for?"). | ||
Options( | ||
huh.NewOption("Carrot", "carrot"), | ||
huh.NewOption("Jicama", "jicama"), | ||
huh.NewOption("Kohlrabi", "kohlrabi"), | ||
huh.NewOption("Fennel", "fennel"), | ||
huh.NewOption("Ginger", "ginger"), | ||
). | ||
Value(&choice), | ||
).WithHideFunc(func() bool { return category != vegetables }), | ||
|
||
huh.NewGroup( | ||
huh.NewSelect[string](). | ||
Title(fmt.Sprintf("Okay, what kind of %s are you in the mood for?", category)). | ||
Options( | ||
huh.NewOption("Coffee", "coffee"), | ||
huh.NewOption("Tea", "tea"), | ||
huh.NewOption("Bubble Tea", "bubble tea"), | ||
huh.NewOption("Agua Fresca", "agua-fresca"), | ||
). | ||
Value(&choice), | ||
).WithHideFunc(func() bool { return category != drinks }), | ||
).Run() | ||
|
||
if err != nil { | ||
fmt.Println("Trouble in food paradise:", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("One %s coming right up!\n", choice) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import "github.com/charmbracelet/huh" | ||
|
||
func main() { | ||
f := huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewInput().Title("Dynamic Help"), | ||
huh.NewInput().Title("Dynamic Help"), | ||
huh.NewInput().Title("Dynamic Help"), | ||
), | ||
) | ||
f.Run() | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Output hide.gif | ||
|
||
Set Width 700 | ||
Set Padding 40 | ||
Set Height 350 | ||
Set FontSize 28 | ||
|
||
Hide | ||
Type "go build ." | ||
Sleep 500ms | ||
Enter | ||
Ctrl+L | ||
Sleep 500ms | ||
Type "clear && ./hide" | ||
Sleep 500ms | ||
Enter | ||
Sleep 500ms | ||
Show | ||
|
||
Type@500ms "llllllll" | ||
|
||
Hide | ||
Type "rm hide" Enter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Output suggestions.gif | ||
|
||
Set Width 1000 | ||
Set Padding 30 | ||
Set Height 275 | ||
Set FontSize 38 | ||
|
||
Hide | ||
Type "go build ." | ||
Sleep 500ms | ||
Enter | ||
Ctrl+L | ||
Sleep 500ms | ||
Type "./input" | ||
Sleep 500ms | ||
Enter | ||
Sleep 500ms | ||
Show | ||
|
||
Sleep 1s | ||
Type@300ms "Curryw" | ||
Sleep 1.5s | ||
Ctrl+E | ||
Sleep 3s | ||
|
||
Hide | ||
Type "rm input" | ||
Enter | ||
Sleep 0.5s | ||
|
Oops, something went wrong.