mirror of
https://github.com/charmbracelet/gum
synced 2024-06-19 14:05:08 +02:00
gum choose allows the user to be prompted for a choice from a list of choices. For example, let's ask the user to pick a card from a deck. gum choose --height 15 {Ace,King,Queen,Jack,Ten,Nine,Eight,Seven,Six,Five,Four,Three,Two}" of "{Spades,Hearts,Clubs,Diamonds}
50 lines
998 B
Go
50 lines
998 B
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/alecthomas/kong"
|
|
"github.com/charmbracelet/gum/internal/stdin"
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/muesli/termenv"
|
|
)
|
|
|
|
func main() {
|
|
lipgloss.SetColorProfile(termenv.ANSI256)
|
|
gum := &Gum{}
|
|
ctx := kong.Parse(gum,
|
|
kong.Name("gum"),
|
|
kong.Description("Tasty Bubble Gum for your shell."),
|
|
kong.UsageOnError(),
|
|
kong.ConfigureHelp(kong.HelpOptions{
|
|
Compact: true,
|
|
Summary: false,
|
|
}))
|
|
switch ctx.Command() {
|
|
case "input":
|
|
gum.Input.Run()
|
|
case "write":
|
|
gum.Write.Run()
|
|
case "filter":
|
|
gum.Filter.Run()
|
|
case "choose":
|
|
input, _ := stdin.Read()
|
|
gum.Choose.Options = strings.Split(input, "\n")
|
|
gum.Choose.Run()
|
|
case "choose <options>":
|
|
gum.Choose.Run()
|
|
case "spin <command>":
|
|
gum.Spin.Run()
|
|
case "progress":
|
|
gum.Progress.Run()
|
|
case "style":
|
|
input, _ := stdin.Read()
|
|
gum.Style.Text = []string{input}
|
|
gum.Style.Run()
|
|
case "style <text>":
|
|
gum.Style.Run()
|
|
case "join <text>":
|
|
gum.Join.Run()
|
|
}
|
|
}
|