diff --git a/choose/choose.go b/choose/choose.go index 46f5b95..7b050b2 100644 --- a/choose/choose.go +++ b/choose/choose.go @@ -1,3 +1,14 @@ +// Package 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. +// +// 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. +// +// Let's pick from a list of gum flavors: +// +// $ gum choose "Strawberry" "Banana" "Cherry" +// package choose import ( diff --git a/filter/filter.go b/filter/filter.go index ac64917..a054863 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -1,3 +1,14 @@ +// Package filter provides a fuzzy searching text input to allow filtering a +// list of 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. +// +// I.e. let's pick from a list of gum flavors: +// +// $ cat flavors.text | gum filter +// package filter import ( diff --git a/gum.go b/gum.go index f624742..975bc78 100644 --- a/gum.go +++ b/gum.go @@ -13,25 +13,18 @@ import ( // Gum is the command-line interface for Gum. type Gum struct { - // Input provides a shell script interface for the text input bubble. - // https://github.com/charmbracelet/bubbles/tree/master/textinput + // 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. // - // It can be used to prompt the user for some input. The text the user - // entered will be sent to stdout. + // 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. // - // $ gum input --placeholder "What's your favorite gum?" > answer.text + // Let's pick from a list of gum flavors: // - Input input.Options `cmd:"" help:"Prompt for some input"` - - // Write provides a shell script interface for the text area bubble. - // https://github.com/charmbracelet/bubbles/tree/master/textarea + // $ gum choose "Strawberry" "Banana" "Cherry" // - // 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. - // - // $ gum write > output.text - // - Write write.Options `cmd:"" help:"Prompt for long-form text"` + Choose choose.Options `cmd:"" help:"Choose an option from a list of choices"` // Filter provides a fuzzy searching text input to allow filtering a list of // options to select one option. @@ -46,68 +39,15 @@ type Gum struct { // Filter filter.Options `cmd:"" help:"Filter items from a list"` - // 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. + // Input provides a shell script interface for the text input bubble. + // https://github.com/charmbracelet/bubbles/tree/master/textinput // - // 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. + // It can be used to prompt the user for some input. The text the user + // entered will be sent to stdout. // - // Let's pick from a list of gum flavors: + // $ gum input --placeholder "What's your favorite gum?" > answer.text // - // $ gum choose "Strawberry" "Banana" "Cherry" - // - Choose choose.Options `cmd:"" help:"Choose an option from a list of choices"` - - // Spin provides a shell script interface for the spinner bubble. - // https://github.com/charmbracelet/bubbles/tree/master/spinner - // - // 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. - // - // For example, let's do a long running task: - // $ sleep 5 - // - // We can simply prepend a spinner to this task to show it to the user, - // while performing the task / command in the background. - // - // $ gum spin -t "Taking a nap..." -- sleep 5 - // - // The spinner will automatically exit when the task is complete. - Spin spin.Options `cmd:"" help:"Display spinner while running a command"` - - // Progress provides a shell script interface for the progress bubble. - // https://github.com/charmbracelet/bubbles/tree/master/progress - // - // It's useful for indicating that something is happening in the background - // that will end after some set time. - // - Progress progress.Options `cmd:"" help:"Display a progress bar for a certain time"` - - // 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: - // - // $ gum style \ - // --foreground "#FF06B7" --border "double" --align "center" \ - // --width 50 --margin 2 --padding "2 4" \ - // "Bubble Gum (1¢)" "So sweet and so fresh\!" - // - // - // ╔══════════════════════════════════════════════════╗ - // ║ ║ - // ║ ║ - // ║ Bubble Gum (1¢) ║ - // ║ So sweet and so fresh! ║ - // ║ ║ - // ║ ║ - // ╚══════════════════════════════════════════════════╝ - // - Style style.Options `cmd:"" help:"Apply coloring, borders, spacing to text"` + 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 @@ -126,4 +66,68 @@ type Gum struct { // ╚══════════════════════╝╚═════════════╝ // Join join.Options `cmd:"" help:"Join text vertically or horizontally"` + + // Progress provides a shell script interface for the progress bubble. + // https://github.com/charmbracelet/bubbles/tree/master/progress + // + // It's useful for indicating that something is happening in the background + // that will end after some set time. It can be passed an increment value + // which specifies how much the progress bar should move every interval, + // which can also be configured. + // + // $ gum progress --increment 0.1 --interval 250ms + // + Progress progress.Options `cmd:"" help:"Display a progress bar for a certain time"` + + // Spin provides a shell script interface for the spinner bubble. + // https://github.com/charmbracelet/bubbles/tree/master/spinner + // + // 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. + // + // For example, let's do a long running task: $ sleep 5 + // + // We can simply prepend a spinner to this task to show it to the user, + // while performing the task / command in the background. + // + // $ gum spin -t "Taking a nap..." -- sleep 5 + // + // The spinner will automatically exit when the task is complete. + // + Spin spin.Options `cmd:"" help:"Display spinner while running a command"` + + // 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: + // + // $ gum style \ + // --foreground 212 --border double --align center \ + // --width 50 --margin 2 --padding "2 4" \ + // "Bubble Gum (1¢)" "So sweet and so fresh\!" + // + // + // ╔══════════════════════════════════════════════════╗ + // ║ ║ + // ║ ║ + // ║ Bubble Gum (1¢) ║ + // ║ So sweet and so fresh! ║ + // ║ ║ + // ║ ║ + // ╚══════════════════════════════════════════════════╝ + // + Style style.Options `cmd:"" help:"Apply coloring, borders, spacing to text"` + + // Write provides a shell script interface for the text area bubble. + // https://github.com/charmbracelet/bubbles/tree/master/textarea + // + // 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. + // + // $ gum write > output.text + // + Write write.Options `cmd:"" help:"Prompt for long-form text"` } diff --git a/input/input.go b/input/input.go index 8d664be..294bfa9 100644 --- a/input/input.go +++ b/input/input.go @@ -1,3 +1,11 @@ +// Package input provides a shell script interface for the text input bubble. +// https://github.com/charmbracelet/bubbles/tree/master/textinput +// +// It can be used to prompt the user for some input. The text the user entered +// will be sent to stdout. +// +// $ gum input --placeholder "What's your favorite gum?" > answer.text +// package input import ( diff --git a/join/command.go b/join/command.go index d828456..69eb078 100644 --- a/join/command.go +++ b/join/command.go @@ -1,3 +1,19 @@ +// Package 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. +// +// 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. +// +// $ gum join --horizontal "$BUBBLE_BOX" "$GUM_BOX" +// +// ╔══════════════════════╗╔═════════════╗ +// ║ ║║ ║ +// ║ Bubble ║║ Gum ║ +// ║ ║║ ║ +// ╚══════════════════════╝╚═════════════╝ +// package join import ( diff --git a/join/options.go b/join/options.go index 591c88e..6968ec7 100644 --- a/join/options.go +++ b/join/options.go @@ -1,6 +1,6 @@ package join -// Options is the set +// Options is the set of options that can configure a join. type Options struct { Text []string `arg:"" help:"Text to join."` diff --git a/progress/progress.go b/progress/progress.go index 8dbfd36..5d5d44a 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -1,3 +1,13 @@ +// Package progress provides a shell script interface for the progress bubble. +// https://github.com/charmbracelet/bubbles/tree/master/progress +// +// It's useful for indicating that something is happening in the background +// that will end after some set time. It can be passed an increment value which +// specifies how much the progress bar should move every interval, which can +// also be configured. +// +// $ gum progress --increment 0.1 --interval 250ms +// package progress import ( diff --git a/spin/spin.go b/spin/spin.go index 212c938..7ec4586 100644 --- a/spin/spin.go +++ b/spin/spin.go @@ -1,3 +1,18 @@ +// Package spin provides a shell script interface for the spinner bubble. +// https://github.com/charmbracelet/bubbles/tree/master/spinner +// +// 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. +// +// For example, let's do a long running task: $ sleep 5 +// +// We can simply prepend a spinner to this task to show it to the user, while +// performing the task / command in the background. +// +// $ gum spin -t "Taking a nap..." -- sleep 5 +// +// The spinner will automatically exit when the task is complete. +// package spin import ( diff --git a/style/command.go b/style/command.go index c299ae8..2c7d35b 100644 --- a/style/command.go +++ b/style/command.go @@ -1,3 +1,26 @@ +// Package 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: +// +// $ gum style \ +// --foreground 212 --border double --align center \ +// --width 50 --margin 2 --padding "2 4" \ +// "Bubble Gum (1¢)" "So sweet and so fresh\!" +// +// +// ╔══════════════════════════════════════════════════╗ +// ║ ║ +// ║ ║ +// ║ Bubble Gum (1¢) ║ +// ║ So sweet and so fresh! ║ +// ║ ║ +// ║ ║ +// ╚══════════════════════════════════════════════════╝ +// package style import ( diff --git a/style/lipgloss.go b/style/lipgloss.go new file mode 100644 index 0000000..ff1f9a0 --- /dev/null +++ b/style/lipgloss.go @@ -0,0 +1,26 @@ +package style + +import ( + "github.com/charmbracelet/gum/internal/decode" + "github.com/charmbracelet/lipgloss" +) + +// ToLipgloss takes a Styles flag set and returns the corresponding +// lipgloss.Style. +func (s Styles) ToLipgloss() lipgloss.Style { + return lipgloss.NewStyle(). + Background(lipgloss.Color(s.Background)). + Foreground(lipgloss.Color(s.Foreground)). + BorderBackground(lipgloss.Color(s.BorderBackground)). + BorderForeground(lipgloss.Color(s.BorderForeground)). + Align(decode.Align[s.Align]). + Border(border[s.Border]). + Height(s.Height). + Width(s.Width). + Margin(parseMargin(s.Margin)). + Padding(parsePadding(s.Padding)). + Bold(s.Bold). + Faint(s.Faint). + Italic(s.Italic). + Strikethrough(s.Strikethrough) +} diff --git a/style/options.go b/style/options.go index c605aab..9025f16 100644 --- a/style/options.go +++ b/style/options.go @@ -2,6 +2,36 @@ package style // Options is the customization options for the style command. type Options struct { - Text []string `arg:"" optional:"" help:"Text to style"` - Style Styles `help:"Style to apply" embed:""` + Text []string `arg:"" optional:"" help:"Text to which to apply the style"` + Style Styles `embed:""` +} + +// Styles is a flag set of possible styles. +// +// It corresponds to the available options in the lipgloss.Style struct. +// +// This flag set is used in other parts of the application to embed styles for +// components, through embedding and prefixing. +type Styles struct { + // Colors + Background string `help:"Background color of the ${name=element}" default:"${defaultBackground}" hidden:"" group:"Style Flags"` + Foreground string `help:"color of the ${name=element}" default:"${defaultForeground}" group:"Style Flags"` + + // Border + Border string `help:"Border style to apply" enum:"none,hidden,normal,rounded,thick,double" default:"none" hidden:"" group:"Style Flags"` + BorderBackground string `help:"Border background color" hidden:"" group:"Style Flags"` + BorderForeground string `help:"Border foreground color" hidden:"" group:"Style Flags"` + + // Layout + Align string `help:"Text alignment" enum:"left,center,right,bottom,middle,top" default:"left" hidden:"" group:"Style Flags"` + Height int `help:"Height of output" hidden:"" group:"Style Flags"` + Width int `help:"Width of output" hidden:"" group:"Style Flags"` + Margin string `help:"Margin to apply around the text." default:"0 0" hidden:"" group:"Style Flags"` + Padding string `help:"Padding to apply around the text." default:"0 0" hidden:""` + + // Format + Bold bool `help:"Apply bold formatting" hidden:"" group:"Style Flags"` + Faint bool `help:"Apply faint formatting" hidden:"" group:"Style Flags"` + Italic bool `help:"Apply italic formatting" hidden:"" group:"Style Flags"` + Strikethrough bool `help:"Apply strikethrough formatting" hidden:"" group:"Style Flags"` } diff --git a/style/style.go b/style/style.go deleted file mode 100644 index 089d3e0..0000000 --- a/style/style.go +++ /dev/null @@ -1,52 +0,0 @@ -package style - -import ( - "github.com/charmbracelet/gum/internal/decode" - "github.com/charmbracelet/lipgloss" -) - -// Styles is a flag set of possible styles. -// It corresponds to the available options in the lipgloss.Style struct. -type Styles struct { - // Colors - Background string `help:"Background color of the ${name=element}" default:"${defaultBackground}" hidden:"" group:"Style Flags"` - Foreground string `help:"color of the ${name=element}" default:"${defaultForeground}" group:"Style Flags"` - - // Border - Border string `help:"Border style to apply" enum:"none,hidden,normal,rounded,thick,double" default:"none" hidden:"" group:"Style Flags"` - BorderBackground string `help:"Border background color" hidden:"" group:"Style Flags"` - BorderForeground string `help:"Border foreground color" hidden:"" group:"Style Flags"` - - // Layout - Align string `help:"Text alignment" enum:"left,center,right,bottom,middle,top" default:"left" hidden:"" group:"Style Flags"` - Height int `help:"Height of output" hidden:"" group:"Style Flags"` - Width int `help:"Width of output" hidden:"" group:"Style Flags"` - Margin string `help:"Margin to apply around the text." default:"0 0" hidden:"" group:"Style Flags"` - Padding string `help:"Padding to apply around the text." default:"0 0" hidden:""` - - // Format - Bold bool `help:"Apply bold formatting" hidden:"" group:"Style Flags"` - Faint bool `help:"Apply faint formatting" hidden:"" group:"Style Flags"` - Italic bool `help:"Apply italic formatting" hidden:"" group:"Style Flags"` - Strikethrough bool `help:"Apply strikethrough formatting" hidden:"" group:"Style Flags"` -} - -// ToLipgloss takes a Styles flag set and returns the corresponding -// lipgloss.Style. -func (s Styles) ToLipgloss() lipgloss.Style { - return lipgloss.NewStyle(). - Background(lipgloss.Color(s.Background)). - Foreground(lipgloss.Color(s.Foreground)). - BorderBackground(lipgloss.Color(s.BorderBackground)). - BorderForeground(lipgloss.Color(s.BorderForeground)). - Align(decode.Align[s.Align]). - Border(border[s.Border]). - Height(s.Height). - Width(s.Width). - Margin(parseMargin(s.Margin)). - Padding(parsePadding(s.Padding)). - Bold(s.Bold). - Faint(s.Faint). - Italic(s.Italic). - Strikethrough(s.Strikethrough) -} diff --git a/write/write.go b/write/write.go index 41e539f..41d06d8 100644 --- a/write/write.go +++ b/write/write.go @@ -1,3 +1,11 @@ +// Package write provides a shell script interface for the text area bubble. +// https://github.com/charmbracelet/bubbles/tree/master/textarea +// +// 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. +// +// $ gum write > output.text +// package write import (