Skip to content

Commit a8712df

Browse files
authored
Show help with Huh? (#587)
* chore(deps): bump deps * feat: show help using huh? * fix: lint * fix: test.sh
1 parent 00767d2 commit a8712df

File tree

15 files changed

+95
-67
lines changed

15 files changed

+95
-67
lines changed

.golangci-soft.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ linters:
3131
- noctx
3232
- nolintlint
3333
- prealloc
34-
- wrapcheck
3534

3635
# disable default linters, they are already enabled in .golangci.yml
3736
disable:
37+
- wrapcheck
3838
- deadcode
3939
- errcheck
4040
- gosimple

choose/command.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/charmbracelet/gum/internal/stdin"
1515
)
1616

17+
const widthBuffer = 2
18+
1719
// Run provides a shell script interface for choosing between different through
1820
// options.
1921
func (o Options) Run() error {
@@ -55,36 +57,33 @@ func (o Options) Run() error {
5557
}
5658

5759
width := max(widest(o.Options)+
58-
max(lipgloss.Width(o.SelectedPrefix), lipgloss.Width(o.UnselectedPrefix))+
59-
lipgloss.Width(o.Cursor)+1, lipgloss.Width(o.Header)+1)
60+
max(lipgloss.Width(o.SelectedPrefix)+lipgloss.Width(o.UnselectedPrefix))+
61+
lipgloss.Width(o.Cursor)+1, lipgloss.Width(o.Header)+widthBuffer)
6062

6163
if o.Limit > 1 {
6264
var choices []string
63-
err := huh.NewForm(
64-
huh.NewGroup(
65-
huh.NewMultiSelect[string]().
66-
Options(options...).
67-
Title(o.Header).
68-
Filterable(false).
69-
Height(o.Height).
70-
Limit(o.Limit).
71-
Value(&choices),
72-
),
73-
).
65+
66+
field := huh.NewMultiSelect[string]().
67+
Options(options...).
68+
Title(o.Header).
69+
Height(o.Height).
70+
Limit(o.Limit).
71+
Value(&choices)
72+
73+
form := huh.NewForm(huh.NewGroup(field))
74+
75+
err := form.
7476
WithWidth(width).
75-
WithShowHelp(false).
77+
WithShowHelp(o.ShowHelp).
7678
WithTheme(theme).
7779
Run()
80+
7881
if err != nil {
7982
return err
8083
}
8184
if len(choices) > 0 {
8285
s := strings.Join(choices, "\n")
83-
if isatty.IsTerminal(os.Stdout.Fd()) {
84-
fmt.Println(s)
85-
} else {
86-
fmt.Print(ansi.Strip(s))
87-
}
86+
ansiprint(s)
8887
}
8988
return nil
9089
}
@@ -102,7 +101,7 @@ func (o Options) Run() error {
102101
).
103102
WithWidth(width).
104103
WithTheme(theme).
105-
WithShowHelp(false).
104+
WithShowHelp(o.ShowHelp).
106105
Run()
107106

108107
if err != nil {
@@ -128,3 +127,11 @@ func widest(options []string) int {
128127
}
129128
return max
130129
}
130+
131+
func ansiprint(s string) {
132+
if isatty.IsTerminal(os.Stdout.Fd()) {
133+
fmt.Println(s)
134+
} else {
135+
fmt.Print(ansi.Strip(s))
136+
}
137+
}

choose/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ type Options struct {
1414
Ordered bool `help:"Maintain the order of the selected options" env:"GUM_CHOOSE_ORDERED"`
1515
Height int `help:"Height of the list" default:"10" env:"GUM_CHOOSE_HEIGHT"`
1616
Cursor string `help:"Prefix to show on item that corresponds to the cursor position" default:"> " env:"GUM_CHOOSE_CURSOR"`
17-
Header string `help:"Header value" default:"" env:"GUM_CHOOSE_HEADER"`
17+
ShowHelp bool `help:"Show help keybinds" default:"true" negatable:"true" env:"GUM_CHOOSE_SHOW_HELP"`
18+
Header string `help:"Header value" default:"Choose:" env:"GUM_CHOOSE_HEADER"`
1819
CursorPrefix string `help:"Prefix to show on the cursor item (hidden if limit is 1)" default:"• " env:"GUM_CHOOSE_CURSOR_PREFIX"`
1920
SelectedPrefix string `help:"Prefix to show on selected items (hidden if limit is 1)" default:"✓ " env:"GUM_CHOOSE_SELECTED_PREFIX"`
2021
UnselectedPrefix string `help:"Prefix to show on unselected items (hidden if limit is 1)" default:"• " env:"GUM_CHOOSE_UNSELECTED_PREFIX"`

confirm/command.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import (
55
"os"
66

77
"github.com/charmbracelet/huh"
8-
"github.com/charmbracelet/lipgloss"
98
)
109

1110
// Run provides a shell script interface for prompting a user to confirm an
1211
// action with an affirmative or negative answer.
1312
func (o Options) Run() error {
1413
theme := huh.ThemeCharm()
15-
theme.Focused.Base = lipgloss.NewStyle().Margin(0, 1)
1614
theme.Focused.Title = o.PromptStyle.ToLipgloss()
1715
theme.Focused.FocusedButton = o.SelectedStyle.ToLipgloss()
1816
theme.Focused.BlurredButton = o.UnselectedStyle.ToLipgloss()
@@ -29,7 +27,7 @@ func (o Options) Run() error {
2927
),
3028
).
3129
WithTheme(theme).
32-
WithShowHelp(false).
30+
WithShowHelp(o.ShowHelp).
3331
Run()
3432

3533
if err != nil {

confirm/options.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import (
88

99
// Options is the customization options for the confirm command.
1010
type Options struct {
11-
Default bool `help:"Default confirmation action" default:"true"`
12-
Affirmative string `help:"The title of the affirmative action" default:"Yes"`
13-
Negative string `help:"The title of the negative action" default:"No"`
14-
Prompt string `arg:"" help:"Prompt to display." default:"Are you sure?"`
15-
PromptStyle style.Styles `embed:"" prefix:"prompt." help:"The style of the prompt" set:"defaultMargin=1 0 0 1" envprefix:"GUM_CONFIRM_PROMPT_"`
11+
Default bool `help:"Default confirmation action" default:"true"`
12+
Affirmative string `help:"The title of the affirmative action" default:"Yes"`
13+
Negative string `help:"The title of the negative action" default:"No"`
14+
Prompt string `arg:"" help:"Prompt to display." default:"Are you sure?"`
15+
//nolint:staticcheck
16+
PromptStyle style.Styles `embed:"" prefix:"prompt." help:"The style of the prompt" set:"defaultMargin=0 0 0 1" set:"defaultForeground=#7571F9" set:"defaultBold=true" envprefix:"GUM_CONFIRM_PROMPT_"`
1617
//nolint:staticcheck
1718
SelectedStyle style.Styles `embed:"" prefix:"selected." help:"The style of the selected action" set:"defaultBackground=212" set:"defaultForeground=230" set:"defaultPadding=0 3" set:"defaultMargin=0 1" envprefix:"GUM_CONFIRM_SELECTED_"`
1819
//nolint:staticcheck
1920
UnselectedStyle style.Styles `embed:"" prefix:"unselected." help:"The style of the unselected action" set:"defaultBackground=235" set:"defaultForeground=254" set:"defaultPadding=0 3" set:"defaultMargin=0 1" envprefix:"GUM_CONFIRM_UNSELECTED_"`
21+
ShowHelp bool `help:"Show help key binds" negatable:"" default:"true" env:"GUM_CONFIRM_SHOW_HELP"`
2022
Timeout time.Duration `help:"Timeout until confirm returns selected value or default if provided" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
2123
}

examples/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ gum style --foreground 99 --border double --border-foreground 99 --padding "1 2"
4040

4141
# Write
4242
gum write
43-
gum write --width 40 --height 3 --placeholder "Type whatever you want" --prompt "| " --show-cursor-line --show-line-numbers --value "Something..." --base.padding 1 --cursor.foreground 99 --prompt.foreground 99
43+
gum write --width 40 --height 6 --placeholder "Type whatever you want" --prompt "| " --show-cursor-line --show-line-numbers --value "Something..." --base.padding 1 --cursor.foreground 99 --prompt.foreground 99
4444

4545
# Table
4646
gum table < table/example.csv

file/command.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func (o Options) Run() error {
3030
theme.Focused.Directory = o.DirectoryStyle.ToLipgloss()
3131
theme.Focused.SelectedOption = o.SelectedStyle.ToLipgloss()
3232

33+
keymap := huh.NewDefaultKeyMap()
34+
keymap.FilePicker.Open.SetEnabled(false)
35+
3336
// XXX: These should be file selected specific.
3437
theme.Focused.TextInput.Placeholder = o.PermissionsStyle.ToLipgloss()
3538
theme.Focused.TextInput.Prompt = o.CursorStyle.ToLipgloss()
@@ -46,7 +49,8 @@ func (o Options) Run() error {
4649
Value(&path),
4750
),
4851
).
49-
WithShowHelp(false).
52+
WithShowHelp(o.ShowHelp).
53+
WithKeyMap(keymap).
5054
WithTheme(theme).
5155
Run()
5256

file/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Options struct {
1515
All bool `short:"a" help:"Show hidden and 'dot' files" default:"false" env:"GUM_FILE_ALL"`
1616
File bool `help:"Allow files selection" default:"true" env:"GUM_FILE_FILE"`
1717
Directory bool `help:"Allow directories selection" default:"false" env:"GUM_FILE_DIRECTORY"`
18+
ShowHelp bool `help:"Show help key binds" negatable:"" default:"true" env:"GUM_FILE_SHOW_HELP"`
1819

1920
Height int `help:"Maximum number of files to display" default:"10" env:"GUM_FILE_HEIGHT"`
2021
CursorStyle style.Styles `embed:"" prefix:"cursor." help:"The cursor style" set:"defaultForeground=212" envprefix:"GUM_FILE_CURSOR_"`

go.mod

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ require (
66
github.com/alecthomas/kong v0.9.0
77
github.com/alecthomas/mango-kong v0.1.0
88
github.com/charmbracelet/bubbles v0.18.0
9-
github.com/charmbracelet/bubbletea v0.26.1
9+
github.com/charmbracelet/bubbletea v0.26.2
1010
github.com/charmbracelet/glamour v0.7.0
11-
github.com/charmbracelet/huh v0.3.1-0.20240328185852-590ecabc34b9
12-
github.com/charmbracelet/lipgloss v0.10.0
11+
github.com/charmbracelet/huh v0.3.1-0.20240521183146-8c5d66193f2b
12+
github.com/charmbracelet/lipgloss v0.10.1-0.20240515185947-83fa9be7feac
1313
github.com/charmbracelet/log v0.4.0
1414
github.com/mattn/go-isatty v0.0.20
1515
github.com/muesli/reflow v0.3.0
@@ -24,7 +24,9 @@ require (
2424
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
2525
github.com/aymerick/douceur v0.2.0 // indirect
2626
github.com/catppuccin/go v0.2.0 // indirect
27-
github.com/charmbracelet/x/exp/strings v0.0.0-20240328150354-ab9afc214dfd // indirect
27+
github.com/charmbracelet/x/ansi v0.1.1 // indirect
28+
github.com/charmbracelet/x/exp/strings v0.0.0-20240521140335-394a367403ba // indirect
29+
github.com/charmbracelet/x/exp/term v0.0.0-20240521140335-394a367403ba // indirect
2830
github.com/dlclark/regexp2 v1.11.0 // indirect
2931
github.com/dustin/go-humanize v1.0.1 // indirect
3032
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
@@ -39,12 +41,12 @@ require (
3941
github.com/muesli/mango v0.2.0 // indirect
4042
github.com/olekukonko/tablewriter v0.0.5 // indirect
4143
github.com/rivo/uniseg v0.4.7 // indirect
42-
github.com/yuin/goldmark v1.7.0 // indirect
44+
github.com/yuin/goldmark v1.7.1 // indirect
4345
github.com/yuin/goldmark-emoji v1.0.2 // indirect
44-
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
45-
golang.org/x/net v0.22.0 // indirect
46+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
47+
golang.org/x/net v0.25.0 // indirect
4648
golang.org/x/sync v0.7.0 // indirect
47-
golang.org/x/sys v0.19.0 // indirect
48-
golang.org/x/term v0.19.0 // indirect
49-
golang.org/x/text v0.14.0 // indirect
49+
golang.org/x/sys v0.20.0 // indirect
50+
golang.org/x/term v0.20.0 // indirect
51+
golang.org/x/text v0.15.0 // indirect
5052
)

go.sum

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
2-
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
31
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
42
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
53
github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI=
@@ -20,20 +18,22 @@ github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
2018
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
2119
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
2220
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
23-
github.com/charmbracelet/bubbletea v0.26.1 h1:xujcQeF73rh4jwu3+zhfQsvV18x+7zIjlw7/CYbzGJ0=
24-
github.com/charmbracelet/bubbletea v0.26.1/go.mod h1:FzKr7sKoO8iFVcdIBM9J0sJOcQv5nDQaYwsee3kpbgo=
21+
github.com/charmbracelet/bubbletea v0.26.2 h1:Eeb+n75Om9gQ+I6YpbCXQRKHt5Pn4vMwusQpwLiEgJQ=
22+
github.com/charmbracelet/bubbletea v0.26.2/go.mod h1:6I0nZ3YHUrQj7YHIHlM8RySX4ZIthTliMY+W8X8b+Gs=
2523
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
2624
github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps=
27-
github.com/charmbracelet/huh v0.3.1-0.20240328185852-590ecabc34b9 h1:Izr4MC+shs9PpR4MWz/OFA4+ywbKutvPv0eSHJwfn60=
28-
github.com/charmbracelet/huh v0.3.1-0.20240328185852-590ecabc34b9/go.mod h1:x0rYoA1kpsaefXhRJZuxLM+qP4CYyEFE67T3ZGl7zPU=
29-
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
30-
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
25+
github.com/charmbracelet/huh v0.3.1-0.20240521183146-8c5d66193f2b h1:OT/S40SAHYBYExxjYdSC9VWkwb9a9j1ngaKegMS4Ai0=
26+
github.com/charmbracelet/huh v0.3.1-0.20240521183146-8c5d66193f2b/go.mod h1:IQZ2iXx4ATguyE2lDIZfZ7dMIXXk/uNUjS+OPlJU5Aw=
27+
github.com/charmbracelet/lipgloss v0.10.1-0.20240515185947-83fa9be7feac h1:CLy2pziY/9Yp2ylBfcvsd56MhP3fOVs2Vqh/usofTug=
28+
github.com/charmbracelet/lipgloss v0.10.1-0.20240515185947-83fa9be7feac/go.mod h1:1UdRTH9gYgpcdNN5oBtjbu/IzNKtzVtb7sqN1t9LNn8=
3129
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
3230
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
33-
github.com/charmbracelet/x/exp/strings v0.0.0-20240328150354-ab9afc214dfd h1:yTFoT3v/wDWzeoRXt9mIKlslAKfVNr0XdVCOVwRK8ck=
34-
github.com/charmbracelet/x/exp/strings v0.0.0-20240328150354-ab9afc214dfd/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
35-
github.com/charmbracelet/x/exp/term v0.0.0-20240321133156-7faadd06c281 h1:ZYwrF0GAd859tU6oF63T2pIkZVQ4z9BosDVD7jYu93A=
36-
github.com/charmbracelet/x/exp/term v0.0.0-20240321133156-7faadd06c281/go.mod h1:madZtB2OVDOG+ZnLruGITVZceYy047W+BLQ1MNQzbWg=
31+
github.com/charmbracelet/x/ansi v0.1.1 h1:CGAduulr6egay/YVbGc8Hsu8deMg1xZ/bkaXTPi1JDk=
32+
github.com/charmbracelet/x/ansi v0.1.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
33+
github.com/charmbracelet/x/exp/strings v0.0.0-20240521140335-394a367403ba h1:1z2q8zSjXpHkGjg6XXu6e4uR4tf/35DApbWCwZdyay0=
34+
github.com/charmbracelet/x/exp/strings v0.0.0-20240521140335-394a367403ba/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
35+
github.com/charmbracelet/x/exp/term v0.0.0-20240521140335-394a367403ba h1:OIiPXTWfMtq1ln3yFj+HzXBdkTR8HGoX+OYt1dZ6qNE=
36+
github.com/charmbracelet/x/exp/term v0.0.0-20240521140335-394a367403ba/go.mod h1:YBotIGhfoWhHDlnUpJMkjebGV2pdGRCn1Y4/Nk/vVcU=
3737
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3838
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3939
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
@@ -87,23 +87,23 @@ github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8
8787
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
8888
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
8989
github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
90-
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
91-
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
90+
github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U=
91+
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
9292
github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GAsO5s=
9393
github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY=
94-
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
95-
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
96-
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
97-
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
94+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
95+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
96+
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
97+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
9898
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
9999
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
100100
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
101101
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
102-
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
103-
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
104-
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
105-
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
106-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
107-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
102+
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
103+
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
104+
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
105+
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
106+
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
107+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
108108
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
109109
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

input/command.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package input
22

33
import (
44
"fmt"
5+
56
"os"
67

78
tea "github.com/charmbracelet/bubbletea"
@@ -28,6 +29,8 @@ func (o Options) Run() error {
2829
theme.Focused.TextInput.Prompt = o.PromptStyle.ToLipgloss()
2930
theme.Focused.Title = o.HeaderStyle.ToLipgloss()
3031

32+
keymap := huh.NewDefaultKeyMap()
33+
3134
var echoMode huh.EchoMode
3235

3336
if o.Password {
@@ -50,6 +53,8 @@ func (o Options) Run() error {
5053
WithShowHelp(false).
5154
WithWidth(o.Width).
5255
WithTheme(theme).
56+
WithKeyMap(keymap).
57+
WithShowHelp(o.ShowHelp).
5358
WithProgramOptions(tea.WithOutput(os.Stderr)).
5459
Run()
5560

input/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Options struct {
1818
CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"`
1919
Width int `help:"Input width (0 for terminal width)" default:"40" env:"GUM_INPUT_WIDTH"`
2020
Password bool `help:"Mask input characters" default:"false"`
21+
ShowHelp bool `help:"Show help keybinds" default:"true" negatable:"true" env:"GUM_INPUT_SHOW_HELP"`
2122
Header string `help:"Header value" default:"" env:"GUM_INPUT_HEADER"`
2223
HeaderStyle style.Styles `embed:"" prefix:"header." set:"defaultForeground=240" envprefix:"GUM_INPUT_HEADER_"`
2324
Timeout time.Duration `help:"Timeout until input aborts" default:"0" env:"GUM_INPUT_TIMEOUT"`

spin/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (o Options) Run() error {
4343

4444
// If the command succeeds, and we are printing output and we are in a TTY then push the STDOUT we got to the actual
4545
// STDOUT for piping or other things.
46+
//nolint:nestif
4647
if m.status == 0 {
4748
if o.ShowOutput {
4849
// BubbleTea writes the View() to stderr.

write/command.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func (o Options) Run() error {
2525
theme.Focused.TextInput.Placeholder = o.PlaceholderStyle.ToLipgloss()
2626
theme.Focused.TextInput.Prompt = o.PromptStyle.ToLipgloss()
2727

28+
keymap := huh.NewDefaultKeyMap()
29+
keymap.Text.NewLine.SetHelp("ctrl+j", "new line")
30+
2831
err := huh.NewForm(
2932
huh.NewGroup(
3033
huh.NewText().
@@ -38,7 +41,9 @@ func (o Options) Run() error {
3841
WithWidth(o.Width).
3942
WithHeight(o.Height).
4043
WithTheme(theme).
41-
WithShowHelp(false).Run()
44+
WithKeyMap(keymap).
45+
WithShowHelp(o.ShowHelp).
46+
Run()
4247

4348
if err != nil {
4449
return err

write/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Options struct {
1313
ShowLineNumbers bool `help:"Show line numbers" default:"false" env:"GUM_WRITE_SHOW_LINE_NUMBERS"`
1414
Value string `help:"Initial value (can be passed via stdin)" default:"" env:"GUM_WRITE_VALUE"`
1515
CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"`
16+
ShowHelp bool `help:"Show help key binds" negatable:"" default:"true" env:"GUM_WRITE_SHOW_HELP"`
1617
CursorMode string `prefix:"cursor." name:"mode" help:"Cursor mode" default:"blink" enum:"blink,hide,static" env:"GUM_WRITE_CURSOR_MODE"`
1718

1819
BaseStyle style.Styles `embed:"" prefix:"base." envprefix:"GUM_WRITE_BASE_"`

0 commit comments

Comments
 (0)