mirror of
https://github.com/charmbracelet/gum
synced 2024-06-22 23:36:35 +02:00
Merge branch 'charmbracelet:main' into feature/choose/Allow_User_to_select_or_enter_extra_value
This commit is contained in:
commit
5bdf3ab110
2
.github/dependabot.yml
vendored
2
.github/dependabot.yml
vendored
|
@ -4,7 +4,6 @@ updates:
|
|||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
time: "08:00"
|
||||
labels:
|
||||
- "dependencies"
|
||||
commit-message:
|
||||
|
@ -14,7 +13,6 @@ updates:
|
|||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
time: "08:00"
|
||||
labels:
|
||||
- "dependencies"
|
||||
commit-message:
|
||||
|
|
|
@ -87,7 +87,6 @@ func (o Options) Run() error {
|
|||
return fmt.Errorf("unable to run filter: %w", err)
|
||||
}
|
||||
m := tm.(model)
|
||||
|
||||
if m.aborted {
|
||||
return exit.ErrAborted
|
||||
}
|
||||
|
@ -103,6 +102,9 @@ func (o Options) Run() error {
|
|||
fmt.Println(m.matches[m.cursor].Str)
|
||||
}
|
||||
|
||||
if !o.Strict && len(m.textinput.Value()) != 0 && len(m.matches) == 0 {
|
||||
fmt.Println(m.textinput.Value())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ type Options struct {
|
|||
IndicatorStyle style.Styles `embed:"" prefix:"indicator." set:"defaultForeground=212" envprefix:"GUM_FILTER_INDICATOR_"`
|
||||
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"`
|
||||
Strict bool `help:"Only returns if anything matched. Otherwise return Filter" negatable:"true" default:"true" group:"Selection"`
|
||||
SelectedPrefix string `help:"Character to indicate selected items (hidden if limit is 1)" default:" ◉ " env:"GUM_FILTER_SELECTED_PREFIX"`
|
||||
SelectedPrefixStyle style.Styles `embed:"" prefix:"selected-indicator." set:"defaultForeground=212" envprefix:"GUM_FILTER_SELECTED_PREFIX_"`
|
||||
UnselectedPrefix string `help:"Character to indicate unselected items (hidden if limit is 1)" default:" ○ " env:"GUM_FILTER_UNSELECTED_PREFIX"`
|
||||
|
|
|
@ -6,16 +6,27 @@
|
|||
package style
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
)
|
||||
|
||||
// Run provides a shell script interface for the Lip Gloss styling.
|
||||
// https://github.com/charmbracelet/lipgloss
|
||||
func (o Options) Run() error {
|
||||
text := strings.Join(o.Text, "\n")
|
||||
var text string
|
||||
if len(o.Text) > 0 {
|
||||
text = strings.Join(o.Text, "\n")
|
||||
} else {
|
||||
text, _ = stdin.Read()
|
||||
if text == "" {
|
||||
return errors.New("no input provided, see `gum style --help`")
|
||||
}
|
||||
text = strings.TrimSuffix(text, "\n")
|
||||
}
|
||||
fmt.Println(o.Style.ToLipgloss().Render(text))
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue