2022-06-11 01:07:40 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-07-28 21:10:43 +03:00
|
|
|
"github.com/alecthomas/kong"
|
2022-08-05 01:45:19 +03:00
|
|
|
|
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 23:17:47 +03:00
|
|
|
"github.com/charmbracelet/gum/choose"
|
2022-07-20 20:39:22 +03:00
|
|
|
"github.com/charmbracelet/gum/completion"
|
2022-07-26 22:43:26 +03:00
|
|
|
"github.com/charmbracelet/gum/confirm"
|
2022-10-01 01:40:10 +03:00
|
|
|
"github.com/charmbracelet/gum/file"
|
2022-07-08 20:58:14 +03:00
|
|
|
"github.com/charmbracelet/gum/filter"
|
2022-07-14 20:51:26 +03:00
|
|
|
"github.com/charmbracelet/gum/format"
|
2022-07-07 20:26:35 +03:00
|
|
|
"github.com/charmbracelet/gum/input"
|
2022-07-08 02:28:44 +03:00
|
|
|
"github.com/charmbracelet/gum/join"
|
2023-11-08 18:43:50 +03:00
|
|
|
"github.com/charmbracelet/gum/log"
|
2022-07-11 18:05:58 +03:00
|
|
|
"github.com/charmbracelet/gum/man"
|
2022-09-30 19:09:55 +03:00
|
|
|
"github.com/charmbracelet/gum/pager"
|
2022-07-07 20:26:35 +03:00
|
|
|
"github.com/charmbracelet/gum/spin"
|
|
|
|
"github.com/charmbracelet/gum/style"
|
2022-09-30 19:09:55 +03:00
|
|
|
"github.com/charmbracelet/gum/table"
|
2022-07-07 20:26:35 +03:00
|
|
|
"github.com/charmbracelet/gum/write"
|
2022-06-11 01:07:40 +03:00
|
|
|
)
|
|
|
|
|
2022-07-13 05:12:02 +03:00
|
|
|
// Gum is the command-line interface for Gum.
|
2022-07-07 20:26:35 +03:00
|
|
|
type Gum struct {
|
2022-07-28 21:10:43 +03:00
|
|
|
// Version is a flag that can be used to display the version number.
|
2022-08-03 20:44:56 +03:00
|
|
|
Version kong.VersionFlag `short:"v" help:"Print the version number"`
|
2022-07-28 21:10:43 +03:00
|
|
|
|
2022-07-25 21:11:54 +03:00
|
|
|
// Completion generates Gum shell completion scripts.
|
2022-08-03 20:44:56 +03:00
|
|
|
Completion completion.Completion `cmd:"" hidden:"" help:"Request shell completion"`
|
2022-07-20 20:39:22 +03:00
|
|
|
|
2022-07-11 18:05:58 +03:00
|
|
|
// Man is a hidden command that generates Gum man pages.
|
2022-08-03 20:44:56 +03:00
|
|
|
Man man.Man `cmd:"" hidden:"" help:"Generate man pages"`
|
2022-07-11 18:05:58 +03:00
|
|
|
|
2022-07-13 16:55:36 +03:00
|
|
|
// Choose provides an interface to choose one option from a given list of
|
|
|
|
// options. The options can be provided as (new-line separated) stdin or a
|
|
|
|
// list of arguments.
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
// It is different from the filter command as it does not provide a fuzzy
|
|
|
|
// finding input, so it is best used for smaller lists of options.
|
2022-07-06 21:38:40 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
// Let's pick from a list of gum flavors:
|
2022-07-06 21:38:40 +03:00
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum choose "Strawberry" "Banana" "Cherry"
|
2022-07-06 21:38:40 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
Choose choose.Options `cmd:"" help:"Choose an option from a list of choices"`
|
2022-07-06 21:38:40 +03:00
|
|
|
|
2022-07-26 22:43:26 +03:00
|
|
|
// Confirm provides an interface to ask a user to confirm an action.
|
|
|
|
// The user is provided with an interface to choose an affirmative or
|
|
|
|
// negative answer, which is then reflected in the exit code for use in
|
|
|
|
// scripting.
|
|
|
|
//
|
|
|
|
// If the user selects the affirmative answer, the program exits with 0.
|
|
|
|
// If the user selects the negative answer, the program exits with 1.
|
|
|
|
//
|
|
|
|
// I.e. confirm if the user wants to delete a file
|
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum confirm "Are you sure?" && rm file.txt
|
2022-07-26 22:43:26 +03:00
|
|
|
//
|
|
|
|
Confirm confirm.Options `cmd:"" help:"Ask a user to confirm an action"`
|
|
|
|
|
2022-10-01 01:40:10 +03:00
|
|
|
// File provides an interface to pick a file from a folder (tree).
|
|
|
|
// The user is provided a file manager-like interface to navigate, to
|
|
|
|
// select a file.
|
|
|
|
//
|
|
|
|
// Let's pick a file from the current directory:
|
|
|
|
//
|
|
|
|
// $ gum file
|
|
|
|
// $ gum file .
|
|
|
|
//
|
|
|
|
// Let's pick a file from the home directory:
|
|
|
|
//
|
|
|
|
// $ gum file $HOME
|
|
|
|
File file.Options `cmd:"" help:"Pick a file from a folder"`
|
|
|
|
|
2022-07-08 20:58:14 +03:00
|
|
|
// Filter provides a fuzzy searching text input to allow filtering a list of
|
2022-06-11 01:07:40 +03:00
|
|
|
// options to select one option.
|
|
|
|
//
|
|
|
|
// By default it will list all the files (recursively) in the current directory
|
|
|
|
// for the user to choose one, but the script (or user) can provide different
|
|
|
|
// new-line separated options to choose from.
|
|
|
|
//
|
2022-07-07 20:26:35 +03:00
|
|
|
// I.e. let's pick from a list of gum flavors:
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ cat flavors.text | gum filter
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
2022-07-13 05:12:02 +03:00
|
|
|
Filter filter.Options `cmd:"" help:"Filter items from a list"`
|
2022-06-11 01:07:40 +03:00
|
|
|
|
2022-07-14 23:32:40 +03:00
|
|
|
// Format allows you to render styled text from `markdown`, `code`,
|
|
|
|
// `template` strings, or embedded `emoji` strings.
|
|
|
|
// For more information see the format/README.md file.
|
2022-07-14 20:51:26 +03:00
|
|
|
Format format.Options `cmd:"" help:"Format a string using a template"`
|
|
|
|
|
2022-07-13 16:55:36 +03:00
|
|
|
// Input provides a shell script interface for the text input bubble.
|
|
|
|
// https://github.com/charmbracelet/bubbles/tree/master/textinput
|
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 23:17:47 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
// It can be used to prompt the user for some input. The text the user
|
|
|
|
// entered will be sent to stdout.
|
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 23:17:47 +03:00
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum input --placeholder "What's your favorite gum?" > answer.text
|
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 23:17:47 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
Input input.Options `cmd:"" help:"Prompt for some input"`
|
|
|
|
|
|
|
|
// Join provides a shell script interface for the lipgloss JoinHorizontal
|
|
|
|
// and JoinVertical commands. It allows you to join multi-line text to
|
|
|
|
// build different layouts.
|
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 23:17:47 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
// For example, you can place two bordered boxes next to each other:
|
|
|
|
// Note: We wrap the variable in quotes to ensure the new lines are part of a
|
|
|
|
// single argument. Otherwise, the command won't work as expected.
|
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum join --horizontal "$BUBBLE_BOX" "$GUM_BOX"
|
2022-07-13 16:55:36 +03:00
|
|
|
//
|
|
|
|
// ╔══════════════════════╗╔═════════════╗
|
|
|
|
// ║ ║║ ║
|
|
|
|
// ║ Bubble ║║ Gum ║
|
|
|
|
// ║ ║║ ║
|
|
|
|
// ╚══════════════════════╝╚═════════════╝
|
|
|
|
//
|
|
|
|
Join join.Options `cmd:"" help:"Join text vertically or horizontally"`
|
|
|
|
|
2022-09-30 19:09:55 +03:00
|
|
|
// Pager provides a shell script interface for the viewport bubble.
|
|
|
|
// https://github.com/charmbracelet/bubbles/tree/master/viewport
|
|
|
|
//
|
|
|
|
// It allows the user to scroll through content like a pager.
|
2022-10-01 01:40:10 +03:00
|
|
|
//
|
|
|
|
// ╭────────────────────────────────────────────────╮
|
|
|
|
// │ 1 │ Gum Pager │
|
|
|
|
// │ 2 │ ========= │
|
|
|
|
// │ 3 │ │
|
|
|
|
// │ 4 │ ``` │
|
|
|
|
// │ 5 │ gum pager --height 10 --width 25 < text │
|
|
|
|
// │ 6 │ ``` │
|
|
|
|
// │ 7 │ │
|
|
|
|
// │ 8 │ │
|
|
|
|
// ╰────────────────────────────────────────────────╯
|
|
|
|
// ↑/↓: Navigate • q: Quit
|
|
|
|
//
|
2022-09-30 19:09:55 +03:00
|
|
|
Pager pager.Options `cmd:"" help:"Scroll through a file"`
|
|
|
|
|
2022-06-11 01:07:40 +03:00
|
|
|
// Spin provides a shell script interface for the spinner bubble.
|
2022-07-11 17:41:16 +03:00
|
|
|
// https://github.com/charmbracelet/bubbles/tree/master/spinner
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
|
|
|
// It is useful for displaying that some task is running in the background
|
|
|
|
// while consuming it's output so that it is not shown to the user.
|
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
// For example, let's do a long running task: $ sleep 5
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
|
|
|
// We can simply prepend a spinner to this task to show it to the user,
|
|
|
|
// while performing the task / command in the background.
|
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum spin -t "Taking a nap..." -- sleep 5
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
|
|
|
// The spinner will automatically exit when the task is complete.
|
2022-07-07 20:26:35 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
Spin spin.Options `cmd:"" help:"Display spinner while running a command"`
|
2022-07-07 20:26:35 +03:00
|
|
|
|
2022-06-11 01:07:40 +03:00
|
|
|
// Style provides a shell script interface for Lip Gloss.
|
|
|
|
// https://github.com/charmbracelet/lipgloss
|
|
|
|
//
|
|
|
|
// It allows you to use Lip Gloss to style text without needing to use Go.
|
|
|
|
// All of the styling options are available as flags.
|
|
|
|
//
|
|
|
|
// Let's make some text glamorous using bash:
|
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum style \
|
2022-07-13 16:55:36 +03:00
|
|
|
// --foreground 212 --border double --align center \
|
2022-07-07 20:26:35 +03:00
|
|
|
// --width 50 --margin 2 --padding "2 4" \
|
|
|
|
// "Bubble Gum (1¢)" "So sweet and so fresh\!"
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ╔══════════════════════════════════════════════════╗
|
|
|
|
// ║ ║
|
|
|
|
// ║ ║
|
|
|
|
// ║ Bubble Gum (1¢) ║
|
|
|
|
// ║ So sweet and so fresh! ║
|
|
|
|
// ║ ║
|
|
|
|
// ║ ║
|
|
|
|
// ╚══════════════════════════════════════════════════╝
|
2022-06-11 01:07:40 +03:00
|
|
|
//
|
2022-07-13 05:12:02 +03:00
|
|
|
Style style.Options `cmd:"" help:"Apply coloring, borders, spacing to text"`
|
2022-07-08 02:28:44 +03:00
|
|
|
|
2022-09-30 19:09:55 +03:00
|
|
|
// Table provides a shell script interface for the table bubble.
|
|
|
|
// https://github.com/charmbracelet/bubbles/tree/master/table
|
|
|
|
//
|
|
|
|
// It is useful to render tabular (CSV) data in a terminal and allows
|
|
|
|
// the user to select a row from the table.
|
|
|
|
//
|
|
|
|
// Let's render a table of gum flavors:
|
|
|
|
//
|
|
|
|
// $ gum table <<< "Flavor,Price\nStrawberry,$0.50\nBanana,$0.99\nCherry,$0.75"
|
|
|
|
//
|
|
|
|
// Flavor Price
|
|
|
|
// Strawberry $0.50
|
|
|
|
// Banana $0.99
|
|
|
|
// Cherry $0.75
|
|
|
|
//
|
|
|
|
Table table.Options `cmd:"" help:"Render a table of data"`
|
|
|
|
|
2022-07-13 16:55:36 +03:00
|
|
|
// Write provides a shell script interface for the text area bubble.
|
|
|
|
// https://github.com/charmbracelet/bubbles/tree/master/textarea
|
2022-07-08 17:23:45 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
// It can be used to ask the user to write some long form of text
|
|
|
|
// (multi-line) input. The text the user entered will be sent to stdout.
|
2022-07-08 17:23:45 +03:00
|
|
|
//
|
2022-08-05 01:45:19 +03:00
|
|
|
// $ gum write > output.text
|
2022-07-08 02:28:44 +03:00
|
|
|
//
|
2022-07-13 16:55:36 +03:00
|
|
|
Write write.Options `cmd:"" help:"Prompt for long-form text"`
|
2023-11-08 18:43:50 +03:00
|
|
|
|
|
|
|
// Log provides a shell script interface for logging using Log.
|
|
|
|
// https://github.com/charmbracelet/log
|
|
|
|
//
|
|
|
|
// It can be used to log messages to output.
|
|
|
|
//
|
|
|
|
// $ gum log --level info "Hello, world!"
|
|
|
|
//
|
|
|
|
Log log.Options `cmd:"" help:"Log messages to output"`
|
2022-06-11 01:07:40 +03:00
|
|
|
}
|