mirror of
https://github.com/charmbracelet/gum.git
synced 2024-08-15 09:10:20 +03:00
* Add key/value feature for `gum choose` (#530) * trim the space of key and value * using SplitN
This commit is contained in:
parent
9660c743c5
commit
9a3e11f542
@ -33,7 +33,17 @@ func (o Options) Run() error {
|
||||
}
|
||||
|
||||
theme := huh.ThemeCharm()
|
||||
options := huh.NewOptions(o.Options...)
|
||||
options := make([]huh.Option[string], len(o.Options))
|
||||
for i, option := range o.Options {
|
||||
parsed := strings.SplitN(option, o.Deliminator, 2)
|
||||
if len(parsed) == 2 {
|
||||
key := strings.TrimSpace(parsed[0])
|
||||
value := strings.TrimSpace(parsed[1])
|
||||
options[i] = huh.NewOption(key, value)
|
||||
} else {
|
||||
options[i] = huh.NewOption(option, option)
|
||||
}
|
||||
}
|
||||
|
||||
theme.Focused.Base = lipgloss.NewStyle()
|
||||
theme.Focused.Title = o.HeaderStyle.ToLipgloss()
|
||||
|
@ -26,4 +26,5 @@ type Options struct {
|
||||
ItemStyle style.Styles `embed:"" prefix:"item." hidden:"" envprefix:"GUM_CHOOSE_ITEM_"`
|
||||
SelectedItemStyle style.Styles `embed:"" prefix:"selected." set:"defaultForeground=212" envprefix:"GUM_CHOOSE_SELECTED_"`
|
||||
Timeout time.Duration `help:"Timeout until choose returns selected element" default:"0" env:"GUM_CCHOOSE_TIMEOUT"` // including timeout command options [Timeout,...]
|
||||
Deliminator string `help:"Deliminator to split the options to keys and values" default:"=" env:"GUM_CHOOSE_DELIMINATOR"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user