2022-06-11 00:07:40 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
feat: `gum choose`, pick from a list of choices
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}
2022-07-11 22:17:47 +02:00
|
|
|
"strings"
|
|
|
|
|
2022-06-11 00:07:40 +02:00
|
|
|
"github.com/alecthomas/kong"
|
2022-07-07 19:26:35 +02:00
|
|
|
"github.com/charmbracelet/gum/internal/stdin"
|
2022-07-06 18:51:12 +02:00
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
|
|
"github.com/muesli/termenv"
|
2022-06-11 00:07:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-07-06 18:51:12 +02:00
|
|
|
lipgloss.SetColorProfile(termenv.ANSI256)
|
2022-07-07 19:26:35 +02:00
|
|
|
gum := &Gum{}
|
|
|
|
ctx := kong.Parse(gum,
|
|
|
|
kong.Name("gum"),
|
|
|
|
kong.Description("Tasty Bubble Gum for your shell."),
|
2022-06-11 00:07:40 +02:00
|
|
|
kong.UsageOnError(),
|
2022-07-12 22:05:40 +02:00
|
|
|
kong.Vars{
|
|
|
|
"defaultBackground": "",
|
|
|
|
"defaultForeground": "",
|
|
|
|
},
|
|
|
|
)
|
2022-06-11 00:07:40 +02:00
|
|
|
switch ctx.Command() {
|
|
|
|
case "input":
|
2022-07-12 22:30:17 +02:00
|
|
|
v, _ := stdin.Read()
|
|
|
|
if v != "" {
|
|
|
|
gum.Input.Value = v
|
|
|
|
}
|
2022-07-07 19:26:35 +02:00
|
|
|
gum.Input.Run()
|
2022-07-06 20:38:40 +02:00
|
|
|
case "write":
|
2022-07-12 22:30:17 +02:00
|
|
|
v, _ := stdin.Read()
|
|
|
|
if v != "" {
|
|
|
|
gum.Write.Value = v
|
|
|
|
}
|
2022-07-07 19:26:35 +02:00
|
|
|
gum.Write.Run()
|
2022-07-08 19:58:14 +02:00
|
|
|
case "filter":
|
|
|
|
gum.Filter.Run()
|
feat: `gum choose`, pick from a list of choices
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}
2022-07-11 22:17:47 +02:00
|
|
|
case "choose":
|
|
|
|
input, _ := stdin.Read()
|
|
|
|
gum.Choose.Options = strings.Split(input, "\n")
|
|
|
|
gum.Choose.Run()
|
|
|
|
case "choose <options>":
|
|
|
|
gum.Choose.Run()
|
2022-06-11 00:07:40 +02:00
|
|
|
case "spin <command>":
|
2022-07-07 19:26:35 +02:00
|
|
|
gum.Spin.Run()
|
|
|
|
case "progress":
|
|
|
|
gum.Progress.Run()
|
2022-06-11 00:07:40 +02:00
|
|
|
case "style":
|
2022-07-06 19:54:32 +02:00
|
|
|
input, _ := stdin.Read()
|
2022-07-07 19:26:35 +02:00
|
|
|
gum.Style.Text = []string{input}
|
|
|
|
gum.Style.Run()
|
2022-06-11 00:07:40 +02:00
|
|
|
case "style <text>":
|
2022-07-07 19:26:35 +02:00
|
|
|
gum.Style.Run()
|
2022-07-08 01:28:44 +02:00
|
|
|
case "join <text>":
|
|
|
|
gum.Join.Run()
|
2022-06-11 00:07:40 +02:00
|
|
|
}
|
|
|
|
}
|