-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototype using charmbracelet/huh for prompter
Relates cli/cli#8084 Relates #164 With go-survey/survey being unmaintained, this is an initial prototype of using https://github.com/charmbracelet/huh as an optional prompting experience including support for accessiblity needs. Additionally, this commit includes a simple example to demo the existing and new experiences in `examples/prompter/main.go`: - by default, the existing go-survey/survey experience - specifying `GH_PROMPTER=accessible`, the new charmbracelet/huh experience in rich mode - specifying `ACCESSIBLE=1` with `GH_PROMPTER=accessible`, the new charmbracelet/huh experience in accessible mode
- Loading branch information
1 parent
dbd982e
commit c84e162
Showing
6 changed files
with
389 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/cli/go-gh/v2/pkg/prompter" | ||
) | ||
|
||
func main() { | ||
p := prompter.New(os.Stdin, os.Stdout, os.Stderr) | ||
|
||
// Demonstrating single-option select / dropdown prompts | ||
cuisines := []string{"Italian", "Greek", "Indian", "Japanese", "American"} | ||
favorite, err := p.Select("Favorite cuisine?", "Italian", cuisines) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Favorite cuisine: %s\n", cuisines[favorite]) | ||
|
||
// Demonstrating multi-option select / dropdown prompts | ||
favorites, err := p.MultiSelect("Favorite cuisines?", []string{}, cuisines) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
for _, f := range favorites { | ||
fmt.Printf("Favorite cuisine: %s\n", cuisines[f]) | ||
} | ||
|
||
// Demonstrating text input prompts | ||
text, err := p.Input("Favorite meal?", "Breakfast") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Favorite meal: %s\n", text) | ||
|
||
// Demonstrating password input prompts | ||
safeword, err := p.Password("Safe word?") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Safe word: %s\n", safeword) | ||
|
||
// Demonstrating confirmation prompts | ||
confirmation, err := p.Confirm("Are you sure?", false) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Confirmation: %t\n", confirmation) | ||
} |
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
Oops, something went wrong.