Skip to content

Commit

Permalink
Merge pull request #2679 from carapace-sh/gum-updates-v0.15.0
Browse files Browse the repository at this point in the history
gum updates v0.15.0
  • Loading branch information
rsteube authored Jan 16, 2025
2 parents 50b9483 + fa17247 commit cafee0b
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 354 deletions.
34 changes: 8 additions & 26 deletions completers/gum_completer/cmd/choose.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,6 +49,7 @@ func init() {
chooseCmd.Flags().Bool("header.underline", false, "Underline text")
chooseCmd.Flags().String("header.width", "", "Text width")
chooseCmd.Flags().String("height", "", "Height of the list")
chooseCmd.Flags().String("input-delimiter", "", "Option delimiter when reading from STDIN")
chooseCmd.Flags().String("item.align", "", "Text Alignment")
chooseCmd.Flags().String("item.background", "", "Background Color")
chooseCmd.Flags().Bool("item.bold", false, "Bold text")
Expand All @@ -64,11 +65,13 @@ func init() {
chooseCmd.Flags().Bool("item.strikethrough", false, "Strikethrough text")
chooseCmd.Flags().Bool("item.underline", false, "Underline text")
chooseCmd.Flags().String("item.width", "", "Text width")
chooseCmd.Flags().String("label-delimiter", "", "Allows to set a delimiter, so options can be set as label:value")
chooseCmd.Flags().String("limit", "", "Maximum number of options to pick")
chooseCmd.Flags().Bool("no-limit", false, "Pick unlimited number of options (ignores limit)")
chooseCmd.Flags().Bool("ordered", false, "Maintain the order of the selected options")
chooseCmd.Flags().String("output-delimiter", "", "Option delimiter when writing to STDOUT")
chooseCmd.Flags().Bool("select-if-one", false, "Select the given option if there is only one")
chooseCmd.Flags().StringSlice("selected", []string{}, "Options that should start as selected")
chooseCmd.Flags().StringSlice("selected", []string{}, "Options that should start as selected (selects all if given '*')")
chooseCmd.Flags().String("selected-prefix", "", "Prefix to show on selected items (hidden if limit is 1)")
chooseCmd.Flags().String("selected.align", "", "Text Alignment")
chooseCmd.Flags().String("selected.background", "", "Background Color")
Expand All @@ -85,37 +88,16 @@ func init() {
chooseCmd.Flags().Bool("selected.strikethrough", false, "Strikethrough text")
chooseCmd.Flags().Bool("selected.underline", false, "Underline text")
chooseCmd.Flags().String("selected.width", "", "Text width")
chooseCmd.Flags().Bool("show-help", false, "Show help keybinds")
chooseCmd.Flags().Bool("strip-ansi", false, "Strip ANSI sequences when reading from STDIN")
chooseCmd.Flags().String("timeout", "", "Timeout until choose returns selected element")
chooseCmd.Flags().String("unselected-prefix", "", "Prefix to show on unselected items (hidden if limit is 1)")
rootCmd.AddCommand(chooseCmd)

common.AddFlagCompletion(chooseCmd)
carapace.Gen(chooseCmd).FlagCompletion(carapace.ActionMap{
"cursor.align": gum.ActionAlignments(),
"cursor.background": gum.ActionColors(),
"cursor.border": gum.ActionBorders(),
"cursor.border-background": gum.ActionColors(),
"cursor.border-foreground": gum.ActionColors(),
"cursor.foreground": gum.ActionColors(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"item.align": gum.ActionAlignments(),
"item.background": gum.ActionColors(),
"item.border": gum.ActionBorders(),
"item.border-background": gum.ActionColors(),
"item.border-foreground": gum.ActionColors(),
"item.foreground": gum.ActionColors(),
"selected": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionValues(c.Args...).UniqueList(",")
}),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
})
}
27 changes: 27 additions & 0 deletions completers/gum_completer/cmd/common/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package common

import (
"path/filepath"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func AddFlagCompletion(cmd *cobra.Command) {
m := make(carapace.ActionMap)
cmd.Flags().VisitAll(func(f *pflag.Flag) {
switch strings.TrimPrefix(filepath.Ext(f.Name), ".") {
case "background", "foreground", "border-background", "border-foreground":
m[f.Name] = gum.ActionColors()
case "align":
m[f.Name] = gum.ActionAlignments()
case "border":
m[f.Name] = gum.ActionBorders()
}
})

carapace.Gen(cmd).FlagCompletion(m)
}
25 changes: 4 additions & 21 deletions completers/gum_completer/cmd/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -48,6 +48,8 @@ func init() {
confirmCmd.Flags().Bool("selected.strikethrough", false, "Strikethrough text")
confirmCmd.Flags().Bool("selected.underline", false, "Underline text")
confirmCmd.Flags().String("selected.width", "", "Text width")
confirmCmd.Flags().Bool("show-help", false, "Show help key binds")
confirmCmd.Flags().Bool("show-output", false, "Print prompt and chosen action to output")
confirmCmd.Flags().String("timeout", "", "Timeout until confirm returns selected value or default if provided")
confirmCmd.Flags().String("unselected.align", "", "Text Alignment")
confirmCmd.Flags().String("unselected.background", "", "Background Color")
Expand All @@ -66,24 +68,5 @@ func init() {
confirmCmd.Flags().String("unselected.width", "", "Text width")
rootCmd.AddCommand(confirmCmd)

carapace.Gen(confirmCmd).FlagCompletion(carapace.ActionMap{
"prompt.align": gum.ActionAlignments(),
"prompt.background": gum.ActionColors(),
"prompt.border": gum.ActionBorders(),
"prompt.border-background": gum.ActionColors(),
"prompt.border-foreground": gum.ActionColors(),
"prompt.foreground": gum.ActionColors(),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
"unselected.align": gum.ActionAlignments(),
"unselected.background": gum.ActionColors(),
"unselected.border": gum.ActionBorders(),
"unselected.border-background": gum.ActionColors(),
"unselected.border-foreground": gum.ActionColors(),
"unselected.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(confirmCmd)
}
66 changes: 21 additions & 45 deletions completers/gum_completer/cmd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -79,7 +79,24 @@ func init() {
fileCmd.Flags().Bool("file.strikethrough", false, "Strikethrough text")
fileCmd.Flags().Bool("file.underline", false, "Underline text")
fileCmd.Flags().String("file.width", "", "Text width")
fileCmd.Flags().String("header", "", "Header value")
fileCmd.Flags().String("header.align", "", "Text Alignment")
fileCmd.Flags().String("header.background", "", "Background Color")
fileCmd.Flags().Bool("header.bold", false, "Bold text")
fileCmd.Flags().String("header.border", "", "Border Style")
fileCmd.Flags().String("header.border-background", "", "Border Background Color")
fileCmd.Flags().String("header.border-foreground", "", "Border Foreground Color")
fileCmd.Flags().Bool("header.faint", false, "Faint text")
fileCmd.Flags().String("header.foreground", "", "Foreground Color")
fileCmd.Flags().String("header.height", "", "Text height")
fileCmd.Flags().Bool("header.italic", false, "Italicize text")
fileCmd.Flags().String("header.margin", "", "Text margin")
fileCmd.Flags().String("header.padding", "", "Text padding")
fileCmd.Flags().Bool("header.strikethrough", false, "Strikethrough text")
fileCmd.Flags().Bool("header.underline", false, "Underline text")
fileCmd.Flags().String("header.width", "", "Text width")
fileCmd.Flags().String("height", "", "Maximum number of files to display")
fileCmd.Flags().BoolP("permissions", "p", false, "Show file permissions")
fileCmd.Flags().String("permissions.align", "", "Text Alignment")
fileCmd.Flags().String("permissions.background", "", "Background Color")
fileCmd.Flags().Bool("permissions.bold", false, "Bold text")
Expand Down Expand Up @@ -110,6 +127,8 @@ func init() {
fileCmd.Flags().Bool("selected.strikethrough", false, "Strikethrough text")
fileCmd.Flags().Bool("selected.underline", false, "Underline text")
fileCmd.Flags().String("selected.width", "", "Text width")
fileCmd.Flags().Bool("show-help", false, "Show help key binds")
fileCmd.Flags().BoolP("size", "s", false, "Show file size")
fileCmd.Flags().String("symlink.align", "", "Text Alignment")
fileCmd.Flags().String("symlink.background", "", "Background Color")
fileCmd.Flags().Bool("symlink.bold", false, "Bold text")
Expand All @@ -128,50 +147,7 @@ func init() {
fileCmd.Flags().String("timeout", "", "Timeout until command aborts without a selection")
rootCmd.AddCommand(fileCmd)

carapace.Gen(fileCmd).FlagCompletion(carapace.ActionMap{
"cursor.align": gum.ActionAlignments(),
"cursor.background": gum.ActionColors(),
"cursor.border": gum.ActionBorders(),
"cursor.border-background": gum.ActionColors(),
"cursor.border-foreground": gum.ActionColors(),
"cursor.foreground": gum.ActionColors(),
"directory.align": gum.ActionAlignments(),
"directory.background": gum.ActionColors(),
"directory.border": gum.ActionBorders(),
"directory.border-background": gum.ActionColors(),
"directory.border-foreground": gum.ActionColors(),
"directory.foreground": gum.ActionColors(),
"file-size.align": gum.ActionAlignments(),
"file-size.background": gum.ActionColors(),
"file-size.border": gum.ActionBorders(),
"file-size.border-background": gum.ActionColors(),
"file-size.border-foreground": gum.ActionColors(),
"file-size.foreground": gum.ActionColors(),
"file.align": gum.ActionAlignments(),
"file.background": gum.ActionColors(),
"file.border": gum.ActionBorders(),
"file.border-background": gum.ActionColors(),
"file.border-foreground": gum.ActionColors(),
"file.foreground": gum.ActionColors(),
"permissions.align": gum.ActionAlignments(),
"permissions.background": gum.ActionColors(),
"permissions.border": gum.ActionBorders(),
"permissions.border-background": gum.ActionColors(),
"permissions.border-foreground": gum.ActionColors(),
"permissions.foreground": gum.ActionColors(),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
"symlink.align": gum.ActionAlignments(),
"symlink.background": gum.ActionColors(),
"symlink.border": gum.ActionBorders(),
"symlink.border-background": gum.ActionColors(),
"symlink.border-foreground": gum.ActionColors(),
"symlink.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(fileCmd)

carapace.Gen(fileCmd).PositionalCompletion(
carapace.ActionDirectories(),
Expand Down
69 changes: 10 additions & 59 deletions completers/gum_completer/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -30,7 +30,8 @@ func init() {
filterCmd.Flags().Bool("cursor-text.strikethrough", false, "Strikethrough text")
filterCmd.Flags().Bool("cursor-text.underline", false, "Underline text")
filterCmd.Flags().String("cursor-text.width", "", "Text width")
filterCmd.Flags().Bool("fuzzy", false, "Enable fuzzy matching")
filterCmd.Flags().Bool("fuzzy", false, "Enable fuzzy matching; otherwise match from start of word")
filterCmd.Flags().Bool("fuzzy-sort", false, "Sort fuzzy results by their scores")
filterCmd.Flags().String("header", "", "Header value")
filterCmd.Flags().String("header.align", "", "Text Alignment")
filterCmd.Flags().String("header.background", "", "Background Color")
Expand Down Expand Up @@ -64,6 +65,7 @@ func init() {
filterCmd.Flags().Bool("indicator.strikethrough", false, "Strikethrough text")
filterCmd.Flags().Bool("indicator.underline", false, "Underline text")
filterCmd.Flags().String("indicator.width", "", "Text width")
filterCmd.Flags().String("input-delimiter", "", "Option delimiter when reading from STDIN")
filterCmd.Flags().String("limit", "", "Maximum number of options to pick")
filterCmd.Flags().String("match.align", "", "Text Alignment")
filterCmd.Flags().String("match.background", "", "Background Color")
Expand All @@ -81,6 +83,7 @@ func init() {
filterCmd.Flags().Bool("match.underline", false, "Underline text")
filterCmd.Flags().String("match.width", "", "Text width")
filterCmd.Flags().Bool("no-limit", false, "Pick unlimited number of options (ignores limit)")
filterCmd.Flags().String("output-delimiter", "", "Option delimiter when writing to STDOUT")
filterCmd.Flags().String("placeholder", "", "Placeholder value")
filterCmd.Flags().String("placeholder.align", "", "Text Alignment")
filterCmd.Flags().String("placeholder.background", "", "Background Color")
Expand Down Expand Up @@ -115,6 +118,7 @@ func init() {
filterCmd.Flags().String("prompt.width", "", "Text width")
filterCmd.Flags().Bool("reverse", false, "Display from the bottom of the screen")
filterCmd.Flags().Bool("select-if-one", false, "Select the given option if there is only one")
filterCmd.Flags().StringSlice("selected", []string{}, "Options that should start as selected (selects all if given '*')")
filterCmd.Flags().String("selected-indicator.align", "", "Text Alignment")
filterCmd.Flags().String("selected-indicator.background", "", "Background Color")
filterCmd.Flags().Bool("selected-indicator.bold", false, "Bold text")
Expand All @@ -131,8 +135,10 @@ func init() {
filterCmd.Flags().Bool("selected-indicator.underline", false, "Underline text")
filterCmd.Flags().String("selected-indicator.width", "", "Text width")
filterCmd.Flags().String("selected-prefix", "", "Character to indicate selected items (hidden if limit is 1)")
filterCmd.Flags().Bool("sort", false, "Sort the results")
filterCmd.Flags().Bool("show-help", false, "Show help keybinds")
filterCmd.Flags().Bool("sort", false, "Sort fuzzy results by their scores")
filterCmd.Flags().Bool("strict", false, "Only returns if anything matched. Otherwise return Filter")
filterCmd.Flags().Bool("strip-ansi", false, "Strip ANSI sequences when reading from STDIN")
filterCmd.Flags().String("text.align", "", "Text Alignment")
filterCmd.Flags().String("text.background", "", "Background Color")
filterCmd.Flags().Bool("text.bold", false, "Bold text")
Expand Down Expand Up @@ -169,60 +175,5 @@ func init() {
filterCmd.Flags().String("width", "", "Input width")
rootCmd.AddCommand(filterCmd)

carapace.Gen(filterCmd).FlagCompletion(carapace.ActionMap{
"cursor-text.align": gum.ActionAlignments(),
"cursor-text.background": gum.ActionColors(),
"cursor-text.border": gum.ActionBorders(),
"cursor-text.border-background": gum.ActionColors(),
"cursor-text.border-foreground": gum.ActionColors(),
"cursor-text.foreground": gum.ActionColors(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"indicator.align": gum.ActionAlignments(),
"indicator.background": gum.ActionColors(),
"indicator.border": gum.ActionBorders(),
"indicator.border-background": gum.ActionColors(),
"indicator.border-foreground": gum.ActionColors(),
"indicator.foreground": gum.ActionColors(),
"match.align": gum.ActionAlignments(),
"match.background": gum.ActionColors(),
"match.border": gum.ActionBorders(),
"match.border-background": gum.ActionColors(),
"match.border-foreground": gum.ActionColors(),
"match.foreground": gum.ActionColors(),
"placeholder.align": gum.ActionAlignments(),
"placeholder.background": gum.ActionColors(),
"placeholder.border": gum.ActionBorders(),
"placeholder.border-background": gum.ActionColors(),
"placeholder.border-foreground": gum.ActionColors(),
"placeholder.foreground": gum.ActionColors(),
"prompt.align": gum.ActionAlignments(),
"prompt.background": gum.ActionColors(),
"prompt.border": gum.ActionBorders(),
"prompt.border-background": gum.ActionColors(),
"prompt.border-foreground": gum.ActionColors(),
"prompt.foreground": gum.ActionColors(),
"selected-indicator.align": gum.ActionAlignments(),
"selected-indicator.background": gum.ActionColors(),
"selected-indicator.border": gum.ActionBorders(),
"selected-indicator.border-background": gum.ActionColors(),
"selected-indicator.border-foreground": gum.ActionColors(),
"selected-indicator.foreground": gum.ActionColors(),
"text.align": gum.ActionAlignments(),
"text.background": gum.ActionColors(),
"text.border": gum.ActionBorders(),
"text.border-background": gum.ActionColors(),
"text.border-foreground": gum.ActionColors(),
"text.foreground": gum.ActionColors(),
"unselected-prefix.align": gum.ActionAlignments(),
"unselected-prefix.background": gum.ActionColors(),
"unselected-prefix.border": gum.ActionBorders(),
"unselected-prefix.border-background": gum.ActionColors(),
"unselected-prefix.border-foreground": gum.ActionColors(),
"unselected-prefix.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(filterCmd)
}
1 change: 1 addition & 0 deletions completers/gum_completer/cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
carapace.Gen(formatCmd).Standalone()

formatCmd.Flags().StringP("language", "l", "", "Programming language to parse code")
formatCmd.Flags().Bool("strip-ansi", false, "Strip ANSI sequences when reading from STDIN")
formatCmd.Flags().String("theme", "", "Glamour theme to use for markdown formatting")
formatCmd.Flags().StringP("type", "t", "", "Format to use (markdown,template,code,emoji)")
rootCmd.AddCommand(formatCmd)
Expand Down
Loading

0 comments on commit cafee0b

Please sign in to comment.