From 0f8f67f96e52159bc9645a9ffab4004658e4fdc6 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 17 Dec 2024 14:43:24 -0300 Subject: [PATCH] feat(choose): select from stdin (#773) Signed-off-by: Carlos Alexandro Becker --- choose/command.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/choose/command.go b/choose/command.go index 9a621a2..47e3549 100644 --- a/choose/command.go +++ b/choose/command.go @@ -26,8 +26,10 @@ func (o Options) Run() error { verySubduedStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#DDDADA", Dark: "#3C3C3C"}) ) - if len(o.Options) <= 0 { - input, _ := stdin.Read(stdin.StripANSI(o.StripANSI)) + input, _ := stdin.Read(stdin.StripANSI(o.StripANSI)) + if len(o.Options) > 0 && len(o.Selected) == 0 { + o.Selected = strings.Split(input, o.InputDelimiter) + } else if len(o.Options) == 0 { if input == "" { return errors.New("no options provided, see `gum choose --help`") }