mirror of
https://github.com/charmbracelet/gum
synced 2024-06-07 16:22:17 +02:00
feat(choose): --no-limit flag alias
Adds a --no-limit flag as an alias to set the limit to the number of options available.
This commit is contained in:
parent
01404ef586
commit
54f85439fa
|
@ -1,6 +1,7 @@
|
||||||
package choose
|
package choose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -14,6 +15,9 @@ import (
|
||||||
func (o Options) Run() error {
|
func (o Options) Run() error {
|
||||||
if len(o.Options) == 0 {
|
if len(o.Options) == 0 {
|
||||||
input, _ := stdin.Read()
|
input, _ := stdin.Read()
|
||||||
|
if input == "" {
|
||||||
|
return errors.New("no options provided, see `gum choose --help`")
|
||||||
|
}
|
||||||
o.Options = strings.Split(strings.TrimSpace(input), "\n")
|
o.Options = strings.Split(strings.TrimSpace(input), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,12 +28,18 @@ func (o Options) Run() error {
|
||||||
|
|
||||||
// We don't need to display prefixes if we are only picking one option.
|
// We don't need to display prefixes if we are only picking one option.
|
||||||
// Simply displaying the cursor is enough.
|
// Simply displaying the cursor is enough.
|
||||||
if o.Limit == 1 {
|
if o.Limit == 1 && !o.NoLimit {
|
||||||
o.SelectedPrefix = ""
|
o.SelectedPrefix = ""
|
||||||
o.UnselectedPrefix = ""
|
o.UnselectedPrefix = ""
|
||||||
o.CursorPrefix = ""
|
o.CursorPrefix = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we've set no limit then we can simply select as many options as there
|
||||||
|
// are so let's set the limit to the number of options.
|
||||||
|
if o.NoLimit {
|
||||||
|
o.Limit = len(o.Options)
|
||||||
|
}
|
||||||
|
|
||||||
m, err := tea.NewProgram(model{
|
m, err := tea.NewProgram(model{
|
||||||
height: o.Height,
|
height: o.Height,
|
||||||
cursor: o.Cursor,
|
cursor: o.Cursor,
|
||||||
|
|
|
@ -6,7 +6,8 @@ import "github.com/charmbracelet/gum/style"
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Options []string `arg:"" optional:"" help:"Options to choose from."`
|
Options []string `arg:"" optional:"" help:"Options to choose from."`
|
||||||
|
|
||||||
Limit int `help:"Maximum number of options to pick" default:"1"`
|
Limit int `help:"Maximum number of options to pick" default:"1" group:"Selection"`
|
||||||
|
NoLimit bool `help:"Pick unlimited number of options (ignores limit)" group:"Selection"`
|
||||||
Height int `help:"Height of the list" default:"10"`
|
Height int `help:"Height of the list" default:"10"`
|
||||||
Cursor string `help:"Prefix to show on item that corresponds to the cursor position" default:"> "`
|
Cursor string `help:"Prefix to show on item that corresponds to the cursor position" default:"> "`
|
||||||
CursorPrefix string `help:"Prefix to show on the cursor item (hidden if limit is 1)" default:"• "`
|
CursorPrefix string `help:"Prefix to show on the cursor item (hidden if limit is 1)" default:"• "`
|
||||||
|
|
Loading…
Reference in a new issue